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()
}
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,
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
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();
};