Account settings: add a button to show the context menu #3584
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 13 Aug 2015 10:33:20 +0000 (12:33 +0200)
committerOlivier Goffart <ogoffart@woboq.com>
Thu, 13 Aug 2015 10:34:22 +0000 (12:34 +0200)
src/gui/accountsettings.cpp
src/gui/folderstatusdelegate.cpp
src/gui/folderstatusdelegate.h

index d652a88c38eb2aa1507d77273434b2ab5f7c17aa..4fdb5f1fac2f4913cc7bdb43a173c7cfdac33855 100644 (file)
@@ -172,6 +172,14 @@ void AccountSettings::slotFolderActivated( const QModelIndex& indx )
         slotAddFolder();
         return;
     }
+    if (_model->classify(indx) == FolderStatusModel::RootFolder) {
+        // tries to find if we clicked on the '...' button.
+        QTreeView *tv = ui->_folderList;
+        auto pos = tv->mapFromGlobal(QCursor::pos());
+        if (FolderStatusDelegate::optionsButtonRect(tv->visualRect(indx)).contains(pos)) {
+            slotCustomContextMenuRequested(pos);
+        }
+    }
 }
 
 void AccountSettings::slotAddFolder()
index 4f0d757e45ffda96b30c3639bcf80a3b9e7e3108..001e9c09b2571556e2cdadc1e01dd26b56242dd4 100644 (file)
@@ -323,6 +323,16 @@ void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
     }
 
     painter->restore();
+
+    {
+        QStyleOptionToolButton btnOpt;
+        btnOpt.text = QLatin1String("...");
+        btnOpt.state = option.state;
+        btnOpt.state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
+        btnOpt.state |= QStyle::State_Raised;
+        btnOpt.rect = optionsButtonRect(option.rect);
+        QApplication::style()->drawComplexControl( QStyle::CC_ToolButton, &btnOpt, painter );
+    }
 }
 
 bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * model,
@@ -331,4 +341,21 @@ bool FolderStatusDelegate::editorEvent ( QEvent * event, QAbstractItemModel * mo
     return QStyledItemDelegate::editorEvent(event, model, option, index);
 }
 
+QRect FolderStatusDelegate::optionsButtonRect(const QRect &within)
+{
+    QStyleOptionToolButton opt;
+    opt.text = QLatin1String("...");
+    QFontMetrics fm = QFontMetrics(QFont());
+    QSize textSize = fm.size(Qt::TextShowMnemonic, opt.text);
+    opt.rect.setSize(textSize);
+    QSize size = QApplication::style()->sizeFromContents(QStyle::CT_ToolButton, &opt, textSize).
+        expandedTo(QApplication::globalStrut());
+
+    int margin = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
+    return QRect(QPoint(within.right() - size.width() - margin,
+                        within.top() + within.height()/2 - size.height()/2),
+                 size);
+}
+
+
 } // namespace OCC
index a7b679553366ea39123525195a15479399c00fbc..fc7050c724ee8a445b36f1b198b0bfbc50c83d2d 100644 (file)
@@ -51,6 +51,12 @@ public:
     QSize sizeHint( const QStyleOptionViewItem&, const QModelIndex& ) const Q_DECL_OVERRIDE;
     bool editorEvent( QEvent* event, QAbstractItemModel* model, const QStyleOptionViewItem& option,
                       const QModelIndex& index ) Q_DECL_OVERRIDE;
+
+
+    /**
+     * return the position of the option button within the item
+     */
+    static QRect optionsButtonRect(const QRect &within);
 private:
     static QString addFolderText();
 };