From b6b5c513d6d904219f93b47c9d1d41cdbb202fc6 Mon Sep 17 00:00:00 2001 From: Phenom Date: Thu, 28 Jan 2021 09:47:04 +0100 Subject: [PATCH] Fix to get Gxs Group last column stretchable. --- .../src/gui/common/GroupTreeWidget.cpp | 28 +++++----------- .../src/gui/common/GroupTreeWidget.h | 2 -- .../src/gui/common/GroupTreeWidget.ui | 4 +-- .../src/gui/common/RSTreeWidget.cpp | 33 +++++++++++++++---- retroshare-gui/src/gui/common/RSTreeWidget.h | 2 ++ 5 files changed, 38 insertions(+), 31 deletions(-) diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp index dc1d365ec..0f8a2fca8 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.cpp @@ -97,11 +97,11 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) : QTreeWidgetItem *headerItem = ui->treeWidget->headerItem(); headerItem->setText(GTW_COLUMN_NAME, tr("Name")); - headerItem->setText(GTW_COLUMN_UNREAD, tr("Unread")); - headerItem->setText(GTW_COLUMN_POSTS, tr("F Posts")); - headerItem->setText(GTW_COLUMN_POPULARITY, tr("Popularity")); - headerItem->setText(GTW_COLUMN_LAST_POST, tr("Last Post")); - headerItem->setToolTip(GTW_COLUMN_NAME, tr("Name")); + headerItem->setText(GTW_COLUMN_UNREAD, ""); + headerItem->setText(GTW_COLUMN_POSTS, ""); + headerItem->setText(GTW_COLUMN_POPULARITY, ""); + headerItem->setText(GTW_COLUMN_LAST_POST, ""); + headerItem->setToolTip(GTW_COLUMN_NAME, tr("Group Name")); headerItem->setToolTip(GTW_COLUMN_UNREAD, tr("Number of Unread message")); headerItem->setToolTip(GTW_COLUMN_POSTS, tr("Friend's Posts")); headerItem->setToolTip(GTW_COLUMN_POPULARITY, tr("Popularity")); @@ -109,9 +109,9 @@ GroupTreeWidget::GroupTreeWidget(QWidget *parent) : /* Set header resize modes and initial section sizes */ QHeaderView *header = ui->treeWidget->header (); - header->setStretchLastSection(false); - QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_NAME, QHeaderView::Stretch); - header->resizeSection(GTW_COLUMN_NAME, 10*W) ; + header->setStretchLastSection(true); + QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_NAME, QHeaderView::Interactive); + header->resizeSection(GTW_COLUMN_NAME, 40*W) ; QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_UNREAD, QHeaderView::Interactive); header->resizeSection(GTW_COLUMN_UNREAD, 3*W+4) ; QHeaderView_setSectionResizeModeColumn(header, GTW_COLUMN_POSTS, QHeaderView::Interactive); @@ -191,8 +191,6 @@ void GroupTreeWidget::processSettings(bool load) if (load) { // load Settings - bool showHeader = Settings->value("GroupShowHeader", false).toBool(); - actionShowHeader->setChecked(showHeader); // state of order bool ascSort = Settings->value("GroupAscSort", true).toBool(); @@ -230,7 +228,6 @@ void GroupTreeWidget::processSettings(bool load) } } else { // save Settings - Settings->setValue("GroupShowHeader", !(actionShowHeader && actionShowHeader->isChecked())); //False by default // state of order Settings->setValue("GroupAscSort", !(actionSortDescending && actionSortDescending->isChecked())); //True by default @@ -257,10 +254,6 @@ void GroupTreeWidget::initDisplayMenu(QToolButton *toolButton) displayMenu = new QMenu(); QActionGroup *actionGroupAsc = new QActionGroup(displayMenu); - actionShowHeader = displayMenu->addAction(tr("Show Header")); - connect(actionShowHeader, SIGNAL(toggled(bool)), this, SLOT(showHeader(bool))); - actionShowHeader->setCheckable(true); - actionSortDescending = displayMenu->addAction(FilesDefs::getIconFromQtResourcePath(":/images/sort_decrease.png"), tr("Sort Descending Order"), this, SLOT(sort())); actionSortDescending->setCheckable(true); actionSortDescending->setActionGroup(actionGroupAsc); @@ -777,11 +770,6 @@ void GroupTreeWidget::distantSearch() ui->distantSearchLineEdit->clear(); } -void GroupTreeWidget::showHeader(bool toShow) -{ - ui->treeWidget->header()->setVisible(toShow); -} - void GroupTreeWidget::sort() { resort(NULL); diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.h b/retroshare-gui/src/gui/common/GroupTreeWidget.h index dcb48a34e..fe0fa163c 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.h +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.h @@ -140,7 +140,6 @@ private slots: void filterChanged(); void distantSearch(); - void showHeader(bool toShow); void sort(); private: @@ -152,7 +151,6 @@ private: private: QMenu *displayMenu; - QAction *actionShowHeader; QAction *actionSortAscending; QAction *actionSortDescending; QAction *actionSortByName; diff --git a/retroshare-gui/src/gui/common/GroupTreeWidget.ui b/retroshare-gui/src/gui/common/GroupTreeWidget.ui index 5cb90b27d..4e7133b71 100644 --- a/retroshare-gui/src/gui/common/GroupTreeWidget.ui +++ b/retroshare-gui/src/gui/common/GroupTreeWidget.ui @@ -91,7 +91,7 @@ true - + 0 0 @@ -137,7 +137,7 @@ LineEditClear QLineEdit -
gui/common/LineEditClear.h
+
gui/common/LineEditClear.h
RSTreeWidget diff --git a/retroshare-gui/src/gui/common/RSTreeWidget.cpp b/retroshare-gui/src/gui/common/RSTreeWidget.cpp index bcd8eef53..24c8b73df 100644 --- a/retroshare-gui/src/gui/common/RSTreeWidget.cpp +++ b/retroshare-gui/src/gui/common/RSTreeWidget.cpp @@ -250,7 +250,7 @@ QMenu *RSTreeWidget::createStandardContextMenu(QMenu *contextMenu) contextMenu->addSeparator(); } - if(!mContextMenuActions.isEmpty() || mEnableColumnCustomize ||!mContextMenuActions.isEmpty() || !mContextMenuMenus.isEmpty()) { + if(!mContextMenuActions.isEmpty() || !mContextMenuMenus.isEmpty() || mEnableColumnCustomize) { QWidget *widget = new QWidget(contextMenu); widget->setStyleSheet( ".QWidget{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 #FEFEFE, stop:1 #E8E8E8); border: 1px solid #CCCCCC;}"); @@ -279,22 +279,28 @@ QMenu *RSTreeWidget::createStandardContextMenu(QMenu *contextMenu) } if (mEnableColumnCustomize) { + QAction *actShowHeader = contextMenu->addAction(QIcon(), tr("Show Header"), this, SLOT(headerVisible())); + actShowHeader->setCheckable(true); + actShowHeader->setChecked(!isHeaderHidden()); + QMenu *headerMenu = contextMenu->addMenu(QIcon(),tr("Show column...")); QTreeWidgetItem *item = headerItem(); int columnCount = item->columnCount(); for (int column = 0; column < columnCount; ++column) - { + { QMap::const_iterator it = mColumnCustomizable.find(column); if (it != mColumnCustomizable.end() && *it == false) { continue; } - QString txt = item->text(column) ; - if(txt == "") - txt = item->data(column,Qt::UserRole).toString() ; + QString txt = item->text(column) ; + if(txt == "") + txt = item->data(column,Qt::UserRole).toString() ; + if(txt == "") + txt = item->data(column,Qt::ToolTipRole).toString() ; - if(txt=="") - txt = tr("[no title]") ; + if(txt=="") + txt = tr("[no title]") ; QAction *action = headerMenu->addAction(QIcon(), txt, this, SLOT(columnVisible())); action->setCheckable(true); @@ -343,6 +349,19 @@ void RSTreeWidget::headerContextMenuRequested(const QPoint &pos) delete contextMenu; } +void RSTreeWidget::headerVisible() +{ + QAction *action = dynamic_cast(sender()); + if (!action) { + return; + } + + bool visible = action->isChecked(); + setHeaderHidden(!visible); + + emit headerVisibleChanged(visible); +} + void RSTreeWidget::columnVisible() { QAction *action = dynamic_cast(sender()); diff --git a/retroshare-gui/src/gui/common/RSTreeWidget.h b/retroshare-gui/src/gui/common/RSTreeWidget.h index e42024629..47ec0916a 100644 --- a/retroshare-gui/src/gui/common/RSTreeWidget.h +++ b/retroshare-gui/src/gui/common/RSTreeWidget.h @@ -58,6 +58,7 @@ public: signals: void signalMouseMiddleButtonClicked(QTreeWidgetItem *item); + void headerVisibleChanged(bool visible); void columnVisibleChanged(int column, bool visible); private: @@ -66,6 +67,7 @@ private: private slots: void headerContextMenuRequested(const QPoint &pos); + void headerVisible(); void columnVisible(); protected: