Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@woboq.com>2015-07-06 16:41:38 +0300
committerOlivier Goffart <ogoffart@woboq.com>2015-07-06 17:04:06 +0300
commitceddbe248e6e1362cc1d81cbab108122fe31c0bf (patch)
tree7d81f46833549f4e586013ad3b858cffa698d80f /src/gui/folderstatusdelegate.cpp
parentef1f2d2b79df41f48bd30d616f6cebf22fa17f9d (diff)
FolderStatusDelegate: style the Add Folder button
Diffstat (limited to 'src/gui/folderstatusdelegate.cpp')
-rw-r--r--src/gui/folderstatusdelegate.cpp32
1 files changed, 27 insertions, 5 deletions
diff --git a/src/gui/folderstatusdelegate.cpp b/src/gui/folderstatusdelegate.cpp
index 3373ce71c..b8cbc6418 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;
}