[Pkg-owncloud-commits] [owncloud-client] 60/120: Account settings: add a button to show the context menu #3584

Sandro Knauß hefee-guest at moszumanska.debian.org
Mon Aug 24 00:02:45 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit f32c8d0570a9f8a3a808f6a70d322d8c5333a3d5
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Thu Aug 13 12:33:20 2015 +0200

    Account settings: add a button to show the context menu #3584
---
 src/gui/accountsettings.cpp      |  8 ++++++++
 src/gui/folderstatusdelegate.cpp | 27 +++++++++++++++++++++++++++
 src/gui/folderstatusdelegate.h   |  6 ++++++
 3 files changed, 41 insertions(+)

diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp
index d652a88..4fdb5f1 100644
--- a/src/gui/accountsettings.cpp
+++ b/src/gui/accountsettings.cpp
@@ -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()
diff --git a/src/gui/folderstatusdelegate.cpp b/src/gui/folderstatusdelegate.cpp
index 4f0d757..001e9c0 100644
--- a/src/gui/folderstatusdelegate.cpp
+++ b/src/gui/folderstatusdelegate.cpp
@@ -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
diff --git a/src/gui/folderstatusdelegate.h b/src/gui/folderstatusdelegate.h
index a7b6795..fc7050c 100644
--- a/src/gui/folderstatusdelegate.h
+++ b/src/gui/folderstatusdelegate.h
@@ -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();
 };

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list