@@ -54,6 +54,29 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(QWidget *parent) :
5454 connect (ui->clearButton , SIGNAL (clicked ()), this , SLOT (clear ()));
5555}
5656
57+ // recent request table's header signals
58+ void ReceiveCoinsDialog::connectRecentRequestsViewHeadersSignals ()
59+ {
60+ connect (ui->recentRequestsView ->horizontalHeader (),SIGNAL (sectionResized (int ,int ,int )),this ,SLOT (on_sectionResized ()));
61+ connect (ui->recentRequestsView ->horizontalHeader (),SIGNAL (geometriesChanged ()),this ,SLOT (on_geometriesChanged ()));
62+ }
63+
64+ // we need to disconnect these while handling the resize events, otherwise we can enter an infinite loop
65+ void ReceiveCoinsDialog::disconnectRecentRequestsViewHeadersSignals ()
66+ {
67+ disconnect (ui->recentRequestsView ->horizontalHeader (),SIGNAL (sectionResized (int ,int ,int )),this ,SLOT (on_sectionResized ()));
68+ disconnect (ui->recentRequestsView ->horizontalHeader (),SIGNAL (geometriesChanged ()),this ,SLOT (on_geometriesChanged ()));
69+ }
70+
71+ // setup the resize mode, handles compatibility for QT5 and below as the method signatures changed. (refactored here for readability)
72+ void ReceiveCoinsDialog::setRecentRequestViewHeaderResizeMode (int logicalIndex, QHeaderView::ResizeMode resizeMode) {
73+ #if QT_VERSION < 0x050000
74+ ui->recentRequestsView ->horizontalHeader ()->setResizeMode (logicalIndex, resizeMode);
75+ #else
76+ ui->recentRequestsView ->horizontalHeader ()->setSectionResizeMode (logicalIndex, resizeMode);
77+ #endif
78+ }
79+
5780void ReceiveCoinsDialog::setModel (WalletModel *model)
5881{
5982 this ->model = model;
@@ -63,20 +86,23 @@ void ReceiveCoinsDialog::setModel(WalletModel *model)
6386 connect (model->getOptionsModel (), SIGNAL (displayUnitChanged (int )), this , SLOT (updateDisplayUnit ()));
6487 updateDisplayUnit ();
6588
89+ ui->recentRequestsView ->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
6690 ui->recentRequestsView ->setModel (model->getRecentRequestsTableModel ());
6791 ui->recentRequestsView ->setAlternatingRowColors (true );
6892 ui->recentRequestsView ->setSelectionBehavior (QAbstractItemView::SelectRows);
6993 ui->recentRequestsView ->setSelectionMode (QAbstractItemView::ContiguousSelection);
70- ui->recentRequestsView ->horizontalHeader ()->resizeSection (RecentRequestsTableModel::Date, 130 );
71- ui->recentRequestsView ->horizontalHeader ()->resizeSection (RecentRequestsTableModel::Label, 120 );
72- #if QT_VERSION < 0x050000
73- ui->recentRequestsView ->horizontalHeader ()->setResizeMode (RecentRequestsTableModel::Message, QHeaderView::Stretch);
74- #else
75- ui->recentRequestsView ->horizontalHeader ()->setSectionResizeMode (RecentRequestsTableModel::Message, QHeaderView::Stretch);
76- #endif
77- ui->recentRequestsView ->horizontalHeader ()->resizeSection (RecentRequestsTableModel::Amount, 100 );
94+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Date, DATE_COLUMN_WIDTH);
95+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Label, LABEL_COLUMN_WIDTH);
96+ // (last 2 columns are set when the table geometry is ready)
97+
98+ setRecentRequestViewHeaderResizeMode (RecentRequestsTableModel::Message, QHeaderView::Interactive);
99+ setRecentRequestViewHeaderResizeMode (RecentRequestsTableModel::Amount, QHeaderView::Fixed);
100+
101+ // this honors a minimum size while resizing for all columns. Wish they had a method for a single column.
102+ ui->recentRequestsView ->horizontalHeader ()->setMinimumSectionSize (MINIMUM_COLUMN_WIDTH);
78103
79104 model->getRecentRequestsTableModel ()->sort (RecentRequestsTableModel::Date, Qt::DescendingOrder);
105+ connectRecentRequestsViewHeadersSignals (); // now we're ready to handle events on the table header.
80106 }
81107}
82108
@@ -185,6 +211,58 @@ void ReceiveCoinsDialog::on_removeRequestButton_clicked()
185211 model->getRecentRequestsTableModel ()->removeRows (firstIndex.row (), selection.length (), firstIndex.parent ());
186212}
187213
214+ // given a column index, returns the maximum allowable width by substracting the other column's widths from the table's width
215+ // NOTE: works only for the two columns we care for: The last ("Amount"), and second to last ("Message").
216+ // if given another column number, it will always return the remaining width for the last column ("Amount")
217+ int ReceiveCoinsDialog::getRemainingWidthForColumn (int column)
218+ {
219+ int nResult = AMOUNT_MINIMUM_COLUMN_WIDTH;
220+
221+ QTableView* recentRequestsTableView = ui->recentRequestsView ;
222+ QHeaderView* headerView = recentRequestsTableView->horizontalHeader ();
223+ int nTableWidth = recentRequestsTableView->width ();
224+
225+ if (nTableWidth > 0 )
226+ {
227+ int nOtherColsWidth = headerView->sectionSize (RecentRequestsTableModel::Date);
228+ nOtherColsWidth += headerView->sectionSize (RecentRequestsTableModel::Label);
229+ nOtherColsWidth += headerView->sectionSize (column == RecentRequestsTableModel::Amount ? RecentRequestsTableModel::Message : RecentRequestsTableModel::Amount);
230+ nResult = std::max (nResult, nTableWidth - nOtherColsWidth);
231+ }
232+
233+ return nResult;
234+ }
235+
236+
237+ // make sure we don't make the columns wider than the table's viewport's width.
238+ void ReceiveCoinsDialog::adjustRecentRequestsColumnsWidth ()
239+ {
240+ disconnectRecentRequestsViewHeadersSignals ();
241+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Amount, getRemainingWidthForColumn (RecentRequestsTableModel::Amount));
242+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Message, getRemainingWidthForColumn (RecentRequestsTableModel::Message));
243+ connectRecentRequestsViewHeadersSignals ();
244+ }
245+
246+ // when a section is resized this is a slot-proxy for ajustAmountColumnWidth()
247+ void ReceiveCoinsDialog::on_sectionResized ()
248+ {
249+ adjustRecentRequestsColumnsWidth ();
250+ }
251+
252+ // when the table's geometry is ready, we manually perform the Stretch of the "Message" column
253+ // as the "Stretch" resize mode does not allow for interactive resizing.
254+ void ReceiveCoinsDialog::on_geometriesChanged ()
255+ {
256+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Amount, AMOUNT_MINIMUM_COLUMN_WIDTH);
257+ ui->recentRequestsView ->setColumnWidth (RecentRequestsTableModel::Message, getRemainingWidthForColumn (RecentRequestsTableModel::Message));
258+ }
259+
260+ // We override the virtual resizeEvent of the QWidget to adjust tablet's column sizes as the table's width is proportional to the dialog's.
261+ void ReceiveCoinsDialog::resizeEvent (QResizeEvent* event) {
262+ QWidget::resizeEvent (event);
263+ adjustRecentRequestsColumnsWidth ();
264+ }
265+
188266void ReceiveCoinsDialog::keyPressEvent (QKeyEvent *event)
189267{
190268 if (event->key () == Qt::Key_Return)
0 commit comments