[Pkg-owncloud-commits] [owncloud-client] 251/498: FolderStatusDelegate: style the Add Folder button
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:55 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 ceddbe248e6e1362cc1d81cbab108122fe31c0bf
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Mon Jul 6 15:41:38 2015 +0200
FolderStatusDelegate: style the Add Folder button
---
src/gui/folderstatusdelegate.cpp | 32 +++++++++++++++++++++++++++-----
src/gui/folderstatusdelegate.h | 4 +++-
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/src/gui/folderstatusdelegate.cpp b/src/gui/folderstatusdelegate.cpp
index 3373ce7..b8cbc64 100644
--- a/src/gui/folderstatusdelegate.cpp
+++ b/src/gui/folderstatusdelegate.cpp
@@ -28,11 +28,27 @@
namespace OCC {
+QString FolderStatusDelegate::addFolderText()
+{
+ return tr("Add Folder to Synchronize");
+}
+
//alocate each item size in listview.
QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem & option ,
const QModelIndex & index) const
{
- if (static_cast<const FolderStatusModel *>(index.model())->classify(index) != FolderStatusModel::RootFolder) {
+ auto classif = static_cast<const FolderStatusModel *>(index.model())->classify(index);
+ if (classif == FolderStatusModel::AddButton) {
+ QFontMetrics fm(option.font);
+ QStyleOptionButton opt;
+ static_cast<QStyleOption&>(opt) = option;
+ opt.text = addFolderText();
+ return QApplication::style()->sizeFromContents(
+ QStyle::CT_PushButton, &opt, fm.size(Qt::TextSingleLine, opt.text)).
+ expandedTo(QApplication::globalStrut());
+ }
+
+ if (classif != FolderStatusModel::RootFolder) {
return QStyledItemDelegate::sizeHint(option, index);
}
@@ -75,14 +91,20 @@ QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem & option ,
void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
+ QStyledItemDelegate::paint(painter,option,index);
+
if (qvariant_cast<bool>(index.data(AddButton))) {
- painter->drawText(option.rect, "[+ Add Folder]");
+ QSize hint = sizeHint(option, index);
+ QStyleOptionButton opt;
+ static_cast<QStyleOption&>(opt) = option;
+ // only keep the flags interesting for the button:
+ opt.state = QStyle::State_Enabled;
+ opt.text = addFolderText();
+ opt.rect.setWidth(qMin(opt.rect.width(), hint.width()));
+ QApplication::style()->drawControl(QStyle::CE_PushButton, &opt, painter, option.widget);
return;
}
-
- QStyledItemDelegate::paint(painter,option,index);
-
if (static_cast<const FolderStatusModel *>(index.model())->classify(index) != FolderStatusModel::RootFolder) {
return;
}
diff --git a/src/gui/folderstatusdelegate.h b/src/gui/folderstatusdelegate.h
index 6d87da3..1e63b61 100644
--- a/src/gui/folderstatusdelegate.h
+++ b/src/gui/folderstatusdelegate.h
@@ -25,7 +25,7 @@ namespace OCC {
class FolderStatusDelegate : public QStyledItemDelegate
{
Q_OBJECT
- public:
+public:
enum datarole { FolderAliasRole = Qt::UserRole + 100,
FolderPathRole,
@@ -50,6 +50,8 @@ class FolderStatusDelegate : public QStyledItemDelegate
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;
+private:
+ static QString addFolderText();
};
} // namespace OCC
--
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