mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-22 21:15:55 +03:00
Account settings: add a button to show the context menu #3584
This commit is contained in:
parent
b49e9e8f30
commit
f32c8d0570
3 changed files with 41 additions and 0 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue