Changeset 105029 in vbox
- Timestamp:
- Jun 26, 2024 10:58:38 AM (5 months ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/widgets
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp
r105027 r105029 507 507 virtual ~UIPortForwardingView(); 508 508 509 protected: 510 511 /** Handles any Qt @a pEvent. */ 512 virtual bool event(QEvent *pEvent) RT_OVERRIDE; 513 514 protected slots: 515 516 /** Handles rows being inserted. 517 * @param parent Brings the parent under which new rows being inserted. 518 * @param iStart Brings the starting position (inclusive). 519 * @param iStart Brings the end position (inclusive). */ 520 virtual void rowsInserted(const QModelIndex &parent, int iStart, int iEnd) RT_OVERRIDE; 521 522 /** Handles rows being removed. 523 * @param parent Brings the parent for which rows being removed. 524 * @param iStart Brings the starting position (inclusive). 525 * @param iStart Brings the end position (inclusive). */ 526 virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int iStart, int iEnd) RT_OVERRIDE; 527 509 528 private: 510 529 … … 513 532 /** Cleanups everything. */ 514 533 void cleanup(); 534 535 /** Adjusts table contents. */ 536 void adjust(); 515 537 516 538 /** Holds whether this view contains IPv6 rules, not IPv4. */ … … 810 832 } 811 833 834 bool UIPortForwardingView::event(QEvent *pEvent) 835 { 836 /* Process different event-types: */ 837 switch (pEvent->type()) 838 { 839 /* Adjust table on show/resize events: */ 840 case QEvent::Show: 841 case QEvent::Resize: 842 { 843 // WORKAROUND: 844 // Make sure layout requests really processed first of all; 845 // This is required for the 1st show event but let it be .. 846 QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest); 847 adjust(); 848 break; 849 } 850 default: 851 break; 852 } 853 854 /* Call to base-class: */ 855 return QITableView::event(pEvent); 856 } 857 858 void UIPortForwardingView::rowsInserted(const QModelIndex &parent, int iStart, int iEnd) 859 { 860 /* Call to base-class: */ 861 QITableView::rowsInserted(parent, iStart, iEnd); 862 /* Adjust table on rows being inserted: */ 863 adjust(); 864 } 865 866 void UIPortForwardingView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end) 867 { 868 /* Call to base-class: */ 869 QITableView::rowsAboutToBeRemoved(parent, start, end); 870 /* Adjust table on rows being removed: */ 871 adjust(); 872 } 873 812 874 void UIPortForwardingView::prepare() 813 875 { … … 881 943 882 944 945 void UIPortForwardingView::adjust() 946 { 947 horizontalHeader()->setStretchLastSection(false); 948 /* If table is NOT empty: */ 949 if (model()->rowCount()) 950 { 951 /* Resize table to contents size-hint and emit a spare place for first column: */ 952 resizeColumnsToContents(); 953 uint uFullWidth = viewport()->width(); 954 for (uint u = 1; u < UIPortForwardingDataType_Max; ++u) 955 uFullWidth -= horizontalHeader()->sectionSize(u); 956 horizontalHeader()->resizeSection(UIPortForwardingDataType_Name, uFullWidth); 957 } 958 /* If table is empty: */ 959 else 960 { 961 /* Resize table columns to be equal in size: */ 962 uint uFullWidth = viewport()->width(); 963 for (uint u = 0; u < UIPortForwardingDataType_Max; ++u) 964 horizontalHeader()->resizeSection(u, uFullWidth / UIPortForwardingDataType_Max); 965 } 966 horizontalHeader()->setStretchLastSection(true); 967 } 968 883 969 /********************************************************************************************************************************* 884 970 * Class UIPortForwardingTable implementation. * … … 928 1014 m_rules = newRules; 929 1015 m_pTableModel->setRules(m_rules); 930 sltAdjustTable();931 1016 932 1017 /* Restore last chosen item: */ … … 1010 1095 } 1011 1096 1012 bool UIPortForwardingTable::eventFilter(QObject *pObject, QEvent *pEvent)1013 {1014 /* Process table: */1015 if (pObject == m_pTableView)1016 {1017 /* Process different event-types: */1018 switch (pEvent->type())1019 {1020 case QEvent::Show:1021 case QEvent::Resize:1022 {1023 /* Make sure layout requests really processed first of all: */1024 QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);1025 /* Adjust table: */1026 sltAdjustTable();1027 break;1028 }1029 default:1030 break;1031 }1032 }1033 /* Call to base-class: */1034 return QWidget::eventFilter(pObject, pEvent);1035 }1036 1037 1097 void UIPortForwardingTable::sltRetranslateUI() 1038 1098 { … … 1060 1120 m_pTableView->setCurrentIndex(m_pTableModel->index(m_pTableModel->rowCount() - 1, 0)); 1061 1121 sltUpdateActions(); 1062 sltAdjustTable();1063 1122 } 1064 1123 … … 1069 1128 m_pTableView->setCurrentIndex(m_pTableModel->index(m_pTableModel->rowCount() - 1, 0)); 1070 1129 sltUpdateActions(); 1071 sltAdjustTable();1072 1130 } 1073 1131 … … 1077 1135 m_pTableView->setFocus(); 1078 1136 sltUpdateActions(); 1079 sltAdjustTable();1080 1137 } 1081 1138 … … 1104 1161 menu.addAction(m_pActionAdd); 1105 1162 menu.exec(m_pTableView->viewport()->mapToGlobal(pos)); 1106 }1107 1108 void UIPortForwardingTable::sltAdjustTable()1109 {1110 /* If table is NOT empty: */1111 if (m_pTableModel->rowCount())1112 {1113 /* Resize table to contents size-hint and emit a spare place for first column: */1114 m_pTableView->resizeColumnsToContents();1115 uint uFullWidth = m_pTableView->viewport()->width();1116 for (uint u = 1; u < UIPortForwardingDataType_Max; ++u)1117 uFullWidth -= m_pTableView->horizontalHeader()->sectionSize(u);1118 m_pTableView->horizontalHeader()->resizeSection(UIPortForwardingDataType_Name, uFullWidth);1119 }1120 /* If table is empty: */1121 else1122 {1123 /* Resize table columns to be equal in size: */1124 uint uFullWidth = m_pTableView->viewport()->width();1125 for (uint u = 0; u < UIPortForwardingDataType_Max; ++u)1126 m_pTableView->horizontalHeader()->resizeSection(u, uFullWidth / UIPortForwardingDataType_Max);1127 }1128 1163 } 1129 1164 … … 1249 1284 m_pLayout->addWidget(m_pToolBar); 1250 1285 } 1286 1287 /* Update actions finally: */ 1288 sltUpdateActions(); 1251 1289 } 1252 1290 -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h
r105021 r105029 243 243 void makeSureEditorDataCommitted(); 244 244 245 protected:246 247 /** Preprocesses any Qt @a pEvent for passed @a pObject. */248 virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;249 250 245 private slots: 251 246 … … 267 262 /** Handles request to show context-menu in certain @a position. */ 268 263 void sltShowTableContexMenu(const QPoint &position); 269 270 /** Adjusts table column sizes. */271 void sltAdjustTable();272 264 273 265 private:
Note:
See TracChangeset
for help on using the changeset viewer.