diff --git a/src/gui/accountsettings.cpp b/src/gui/accountsettings.cpp index d652a88c3..4fdb5f1fa 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 4f0d757e4..001e9c09b 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 a7b679553..fc7050c72 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(); };