2015-06-15 15:16:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (C) by Klaas Freitag <freitag@kde.org>
|
|
|
|
* Copyright (C) by Olivier Goffart <ogoffart@woboq.com>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "folderstatusdelegate.h"
|
|
|
|
#include "folderstatusmodel.h"
|
2018-10-30 22:35:35 +03:00
|
|
|
#include "folderstatusview.h"
|
2015-06-15 15:16:21 +03:00
|
|
|
#include "folderman.h"
|
|
|
|
#include "accountstate.h"
|
|
|
|
#include <theme.h>
|
|
|
|
#include <account.h>
|
|
|
|
|
|
|
|
#include <QFileIconProvider>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QApplication>
|
2018-10-30 22:35:35 +03:00
|
|
|
#include <QMouseEvent>
|
2015-06-15 15:16:21 +03:00
|
|
|
|
2016-01-13 13:42:49 +03:00
|
|
|
inline static QFont makeAliasFont(const QFont &normalFont)
|
|
|
|
{
|
|
|
|
QFont aliasFont = normalFont;
|
|
|
|
aliasFont.setBold(true);
|
|
|
|
aliasFont.setPointSize(normalFont.pointSize() + 2);
|
|
|
|
return aliasFont;
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:16:21 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2015-11-06 18:10:03 +03:00
|
|
|
FolderStatusDelegate::FolderStatusDelegate()
|
|
|
|
: QStyledItemDelegate()
|
|
|
|
{
|
2019-12-19 21:50:21 +03:00
|
|
|
customizeStyle();
|
2015-11-06 18:10:03 +03:00
|
|
|
}
|
|
|
|
|
2015-07-06 16:41:38 +03:00
|
|
|
QString FolderStatusDelegate::addFolderText()
|
|
|
|
{
|
2015-09-08 14:37:57 +03:00
|
|
|
return tr("Add Folder Sync Connection");
|
2015-07-06 16:41:38 +03:00
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:19 +03:00
|
|
|
// allocate each item size in listview.
|
2015-06-15 15:16:21 +03:00
|
|
|
QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const
|
|
|
|
{
|
2016-01-13 13:42:49 +03:00
|
|
|
QFont aliasFont = makeAliasFont(option.font);
|
2015-08-20 14:25:19 +03:00
|
|
|
QFont font = option.font;
|
|
|
|
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
|
2015-07-06 16:41:38 +03:00
|
|
|
auto classif = static_cast<const FolderStatusModel *>(index.model())->classify(index);
|
|
|
|
if (classif == FolderStatusModel::AddButton) {
|
2016-01-19 19:39:43 +03:00
|
|
|
const int margins = aliasFm.height(); // same as 2*aliasMargin of paint
|
2017-11-23 19:38:31 +03:00
|
|
|
QFontMetrics fm(qApp->font("QPushButton"));
|
2015-07-06 16:41:38 +03:00
|
|
|
QStyleOptionButton opt;
|
|
|
|
static_cast<QStyleOption &>(opt) = option;
|
|
|
|
opt.text = addFolderText();
|
|
|
|
return QApplication::style()->sizeFromContents(
|
|
|
|
QStyle::CT_PushButton, &opt, fm.size(Qt::TextSingleLine, opt.text))
|
2015-08-20 14:25:19 +03:00
|
|
|
.expandedTo(QApplication::globalStrut())
|
2016-01-13 13:57:15 +03:00
|
|
|
+ QSize(0, margins);
|
2015-07-06 16:41:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (classif != FolderStatusModel::RootFolder) {
|
2015-06-15 15:16:21 +03:00
|
|
|
return QStyledItemDelegate::sizeHint(option, index);
|
|
|
|
}
|
|
|
|
|
2015-07-06 15:44:53 +03:00
|
|
|
// calc height
|
2016-01-13 13:42:49 +03:00
|
|
|
int h = rootFolderHeightWithoutErrors(fm, aliasFm);
|
2017-07-12 15:50:51 +03:00
|
|
|
// this already includes the bottom margin
|
2016-01-13 13:42:49 +03:00
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
// add some space to show an conflict indicator.
|
|
|
|
int margin = fm.height() / 4;
|
|
|
|
if (!qvariant_cast<QStringList>(index.data(FolderConflictMsg)).isEmpty()) {
|
|
|
|
QStringList msgs = qvariant_cast<QStringList>(index.data(FolderConflictMsg));
|
|
|
|
h += margin + 2 * margin + msgs.count() * fm.height();
|
|
|
|
}
|
2016-01-13 13:42:49 +03:00
|
|
|
// add some space to show an error condition.
|
|
|
|
if (!qvariant_cast<QStringList>(index.data(FolderErrorMsg)).isEmpty()) {
|
|
|
|
QStringList errMsgs = qvariant_cast<QStringList>(index.data(FolderErrorMsg));
|
2017-07-12 15:50:51 +03:00
|
|
|
h += margin + 2 * margin + errMsgs.count() * fm.height();
|
2016-01-13 13:42:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return QSize(0, h);
|
|
|
|
}
|
|
|
|
|
|
|
|
int FolderStatusDelegate::rootFolderHeightWithoutErrors(const QFontMetrics &fm, const QFontMetrics &aliasFm)
|
|
|
|
{
|
|
|
|
const int aliasMargin = aliasFm.height() / 2;
|
|
|
|
const int margin = fm.height() / 4;
|
2017-05-17 11:55:42 +03:00
|
|
|
|
2015-07-06 15:44:53 +03:00
|
|
|
int h = aliasMargin; // margin to top
|
|
|
|
h += aliasFm.height(); // alias
|
|
|
|
h += margin; // between alias and local path
|
|
|
|
h += fm.height(); // local path
|
|
|
|
h += margin; // between local and remote path
|
|
|
|
h += fm.height(); // remote path
|
2017-07-12 15:50:51 +03:00
|
|
|
h += margin; // bottom margin
|
2016-01-13 13:42:49 +03:00
|
|
|
return h;
|
2015-06-15 15:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const
|
|
|
|
{
|
2018-10-30 22:35:35 +03:00
|
|
|
if (index.data(AddButton).toBool()) {
|
|
|
|
const_cast<QStyleOptionViewItem &>(option).showDecorationSelected = false;
|
|
|
|
}
|
|
|
|
|
2015-07-06 16:41:38 +03:00
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
|
|
|
|
2016-01-07 15:37:46 +03:00
|
|
|
auto textAlign = Qt::AlignLeft;
|
|
|
|
|
2016-01-13 13:42:49 +03:00
|
|
|
QFont aliasFont = makeAliasFont(option.font);
|
2015-08-20 14:25:19 +03:00
|
|
|
QFont subFont = option.font;
|
|
|
|
QFont errorFont = subFont;
|
|
|
|
QFont progressFont = subFont;
|
|
|
|
|
|
|
|
progressFont.setPointSize(subFont.pointSize() - 2);
|
|
|
|
|
|
|
|
QFontMetrics subFm(subFont);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
QFontMetrics progressFm(progressFont);
|
|
|
|
|
|
|
|
int aliasMargin = aliasFm.height() / 2;
|
|
|
|
int margin = subFm.height() / 4;
|
|
|
|
|
2015-07-14 12:03:25 +03:00
|
|
|
if (index.data(AddButton).toBool()) {
|
2015-07-06 16:41:38 +03:00
|
|
|
QStyleOptionButton opt;
|
|
|
|
static_cast<QStyleOption &>(opt) = option;
|
2018-10-30 22:35:35 +03:00
|
|
|
if (opt.state & QStyle::State_Enabled && opt.state & QStyle::State_MouseOver && index == _pressedIndex) {
|
|
|
|
opt.state |= QStyle::State_Sunken;
|
|
|
|
} else {
|
|
|
|
opt.state |= QStyle::State_Raised;
|
|
|
|
}
|
2015-07-06 16:41:38 +03:00
|
|
|
opt.text = addFolderText();
|
2018-10-30 22:35:35 +03:00
|
|
|
opt.rect = addButtonRect(option.rect, option.direction);
|
2017-11-23 19:38:31 +03:00
|
|
|
painter->save();
|
|
|
|
painter->setFont(qApp->font("QPushButton"));
|
2017-09-13 07:26:56 +03:00
|
|
|
QApplication::style()->drawControl(QStyle::CE_PushButton, &opt, painter, option.widget);
|
2017-11-23 19:38:31 +03:00
|
|
|
painter->restore();
|
2015-07-06 15:44:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (static_cast<const FolderStatusModel *>(index.model())->classify(index) != FolderStatusModel::RootFolder) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
QIcon statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
|
2015-08-12 10:08:30 +03:00
|
|
|
QString aliasText = qvariant_cast<QString>(index.data(HeaderRole));
|
2015-07-06 15:44:53 +03:00
|
|
|
QString pathText = qvariant_cast<QString>(index.data(FolderPathRole));
|
|
|
|
QString remotePath = qvariant_cast<QString>(index.data(FolderSecondPathRole));
|
2017-07-12 15:50:51 +03:00
|
|
|
QStringList conflictTexts = qvariant_cast<QStringList>(index.data(FolderConflictMsg));
|
2015-07-06 15:44:53 +03:00
|
|
|
QStringList errorTexts = qvariant_cast<QStringList>(index.data(FolderErrorMsg));
|
|
|
|
|
|
|
|
int overallPercent = qvariant_cast<int>(index.data(SyncProgressOverallPercent));
|
|
|
|
QString overallString = qvariant_cast<QString>(index.data(SyncProgressOverallString));
|
|
|
|
QString itemString = qvariant_cast<QString>(index.data(SyncProgressItemString));
|
|
|
|
int warningCount = qvariant_cast<int>(index.data(WarningCount));
|
|
|
|
bool syncOngoing = qvariant_cast<bool>(index.data(SyncRunning));
|
2019-01-23 01:16:57 +03:00
|
|
|
QDateTime syncDate = qvariant_cast<QDateTime>(index.data(SyncDate));
|
2016-01-06 12:56:07 +03:00
|
|
|
bool syncEnabled = qvariant_cast<bool>(index.data(FolderAccountConnected));
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
QRect iconRect = option.rect;
|
|
|
|
QRect aliasRect = option.rect;
|
|
|
|
|
|
|
|
iconRect.setLeft(option.rect.left() + aliasMargin);
|
|
|
|
iconRect.setTop(iconRect.top() + aliasMargin); // (iconRect.height()-iconsize.height())/2);
|
|
|
|
|
|
|
|
// alias box
|
|
|
|
aliasRect.setTop(aliasRect.top() + aliasMargin);
|
|
|
|
aliasRect.setBottom(aliasRect.top() + aliasFm.height());
|
|
|
|
aliasRect.setRight(aliasRect.right() - aliasMargin);
|
|
|
|
|
|
|
|
// remote directory box
|
|
|
|
QRect remotePathRect = aliasRect;
|
|
|
|
remotePathRect.setTop(aliasRect.bottom() + margin);
|
|
|
|
remotePathRect.setBottom(remotePathRect.top() + subFm.height());
|
|
|
|
|
|
|
|
// local directory box
|
|
|
|
QRect localPathRect = remotePathRect;
|
|
|
|
localPathRect.setTop(remotePathRect.bottom() + margin);
|
|
|
|
localPathRect.setBottom(localPathRect.top() + subFm.height());
|
|
|
|
|
|
|
|
iconRect.setBottom(localPathRect.bottom());
|
|
|
|
iconRect.setWidth(iconRect.height());
|
|
|
|
|
|
|
|
int nextToIcon = iconRect.right() + aliasMargin;
|
|
|
|
aliasRect.setLeft(nextToIcon);
|
|
|
|
localPathRect.setLeft(nextToIcon);
|
|
|
|
remotePathRect.setLeft(nextToIcon);
|
|
|
|
|
|
|
|
int iconSize = iconRect.width();
|
|
|
|
|
2016-01-13 13:57:15 +03:00
|
|
|
auto optionsButtonVisualRect = optionsButtonRect(option.rect, option.direction);
|
|
|
|
|
2015-07-06 15:44:53 +03:00
|
|
|
QPixmap pm = statusIcon.pixmap(iconSize, iconSize, syncEnabled ? QIcon::Normal : QIcon::Disabled);
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawPixmap(QStyle::visualRect(option.direction, option.rect, iconRect).left(),
|
|
|
|
iconRect.top(), pm);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
// only show the warning icon if the sync is running. Otherwise its
|
|
|
|
// encoded in the status icon.
|
|
|
|
if (warningCount > 0 && syncOngoing) {
|
|
|
|
QRect warnRect;
|
|
|
|
warnRect.setLeft(iconRect.left());
|
|
|
|
warnRect.setTop(iconRect.bottom() - 17);
|
|
|
|
warnRect.setWidth(16);
|
|
|
|
warnRect.setHeight(16);
|
|
|
|
|
2020-01-18 19:47:17 +03:00
|
|
|
QIcon warnIcon(":/client/theme/warning");
|
2015-07-06 15:44:53 +03:00
|
|
|
QPixmap pm = warnIcon.pixmap(16, 16, syncEnabled ? QIcon::Normal : QIcon::Disabled);
|
2016-01-07 15:37:46 +03:00
|
|
|
warnRect = QStyle::visualRect(option.direction, option.rect, warnRect);
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->drawPixmap(QPoint(warnRect.left(), warnRect.top()), pm);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto palette = option.palette;
|
2015-06-15 15:16:21 +03:00
|
|
|
|
2015-07-06 15:44:53 +03:00
|
|
|
if (qApp->style()->inherits("QWindowsVistaStyle")) {
|
|
|
|
// Hack: Windows Vista's light blue is not contrasting enough for white
|
|
|
|
|
|
|
|
// (code from QWindowsVistaStyle::drawControl for CE_ItemViewItem)
|
|
|
|
palette.setColor(QPalette::All, QPalette::HighlightedText, palette.color(QPalette::Active, QPalette::Text));
|
|
|
|
palette.setColor(QPalette::All, QPalette::Highlight, palette.base().color().darker(108));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QPalette::ColorGroup cg = option.state & QStyle::State_Enabled
|
|
|
|
? QPalette::Normal
|
|
|
|
: QPalette::Disabled;
|
|
|
|
if (cg == QPalette::Normal && !(option.state & QStyle::State_Active))
|
|
|
|
cg = QPalette::Inactive;
|
|
|
|
|
|
|
|
if (option.state & QStyle::State_Selected) {
|
|
|
|
painter->setPen(palette.color(cg, QPalette::HighlightedText));
|
|
|
|
} else {
|
|
|
|
painter->setPen(palette.color(cg, QPalette::Text));
|
|
|
|
}
|
|
|
|
QString elidedAlias = aliasFm.elidedText(aliasText, Qt::ElideRight, aliasRect.width());
|
|
|
|
painter->setFont(aliasFont);
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, aliasRect), textAlign, elidedAlias);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2015-10-27 14:52:33 +03:00
|
|
|
const bool showProgess = !overallString.isEmpty() || !itemString.isEmpty();
|
|
|
|
if (!showProgess) {
|
|
|
|
painter->setFont(subFont);
|
2016-01-21 11:56:01 +03:00
|
|
|
QString elidedRemotePathText = subFm.elidedText(
|
2019-01-23 01:16:57 +03:00
|
|
|
tr("Synchronized with local folder (%1)").arg(syncDate.toTimeSpec(Qt::LocalTime).toString(Qt::SystemLocaleShortDate)),
|
2016-01-21 11:56:01 +03:00
|
|
|
Qt::ElideRight, remotePathRect.width());
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, remotePathRect),
|
|
|
|
textAlign, elidedRemotePathText);
|
2016-01-21 11:56:01 +03:00
|
|
|
|
2015-10-27 14:52:33 +03:00
|
|
|
QString elidedPathText = subFm.elidedText(pathText, Qt::ElideMiddle, localPathRect.width());
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, localPathRect),
|
|
|
|
textAlign, elidedPathText);
|
2015-07-06 15:44:53 +03:00
|
|
|
}
|
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
int h = iconRect.bottom() + margin;
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
// paint an error overlay if there is an error string or conflict string
|
|
|
|
auto drawTextBox = [&](const QStringList &texts, QColor color) {
|
|
|
|
QRect rect = localPathRect;
|
|
|
|
rect.setLeft(iconRect.left());
|
|
|
|
rect.setTop(h);
|
|
|
|
rect.setHeight(texts.count() * subFm.height() + 2 * margin);
|
|
|
|
rect.setRight(option.rect.right() - margin);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2019-12-23 16:29:34 +03:00
|
|
|
// save previous state to not mess up colours with the background (fixes issue: https://github.com/nextcloud/desktop/issues/1237)
|
|
|
|
auto oldBrush = painter->brush();
|
|
|
|
auto oldPen = painter->pen();
|
|
|
|
auto oldFont = painter->font();
|
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
painter->setBrush(color);
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->setPen(QColor(0xaa, 0xaa, 0xaa));
|
2017-07-12 15:50:51 +03:00
|
|
|
painter->drawRoundedRect(QStyle::visualRect(option.direction, option.rect, rect),
|
2016-01-07 15:37:46 +03:00
|
|
|
4, 4);
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->setPen(Qt::white);
|
|
|
|
painter->setFont(errorFont);
|
2017-07-12 15:50:51 +03:00
|
|
|
QRect textRect(rect.left() + margin,
|
|
|
|
rect.top() + margin,
|
|
|
|
rect.width() - 2 * margin,
|
2016-01-07 19:56:14 +03:00
|
|
|
subFm.height());
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
foreach (QString eText, texts) {
|
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, textRect), textAlign,
|
|
|
|
subFm.elidedText(eText, Qt::ElideLeft, textRect.width()));
|
|
|
|
textRect.translate(0, textRect.height());
|
2015-07-06 15:44:53 +03:00
|
|
|
}
|
|
|
|
|
2019-12-23 16:29:34 +03:00
|
|
|
// restore previous state
|
|
|
|
painter->setBrush(oldBrush);
|
|
|
|
painter->setPen(oldPen);
|
|
|
|
painter->setFont(oldFont);
|
|
|
|
|
2017-07-12 15:50:51 +03:00
|
|
|
h = rect.bottom() + margin;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!conflictTexts.isEmpty())
|
|
|
|
drawTextBox(conflictTexts, QColor(0xba, 0xba, 0x4d));
|
|
|
|
if (!errorTexts.isEmpty())
|
|
|
|
drawTextBox(errorTexts, QColor(0xbb, 0x4d, 0x4d));
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
// Sync File Progress Bar: Show it if syncFile is not empty.
|
2015-10-27 14:52:33 +03:00
|
|
|
if (showProgess) {
|
2015-07-06 15:44:53 +03:00
|
|
|
int fileNameTextHeight = subFm.boundingRect(tr("File")).height();
|
2016-01-21 11:56:01 +03:00
|
|
|
int barHeight = 7; // same height as quota bar
|
2016-01-13 13:57:15 +03:00
|
|
|
int overallWidth = option.rect.right() - aliasMargin - optionsButtonVisualRect.width() - nextToIcon;
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
painter->save();
|
|
|
|
|
|
|
|
// Overall Progress Bar.
|
|
|
|
QRect pBRect;
|
2015-10-27 14:52:33 +03:00
|
|
|
pBRect.setTop(remotePathRect.top());
|
2015-08-14 12:48:06 +03:00
|
|
|
pBRect.setLeft(nextToIcon);
|
2015-07-06 15:44:53 +03:00
|
|
|
pBRect.setHeight(barHeight);
|
2016-01-21 11:56:01 +03:00
|
|
|
pBRect.setWidth(overallWidth - 2 * margin);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2016-11-15 12:14:50 +03:00
|
|
|
QStyleOptionProgressBar pBarOpt;
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
pBarOpt.state = option.state | QStyle::State_Horizontal;
|
|
|
|
pBarOpt.minimum = 0;
|
|
|
|
pBarOpt.maximum = 100;
|
|
|
|
pBarOpt.progress = overallPercent;
|
|
|
|
pBarOpt.orientation = Qt::Horizontal;
|
2016-01-07 15:37:46 +03:00
|
|
|
pBarOpt.rect = QStyle::visualRect(option.direction, option.rect, pBRect);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &pBarOpt, painter);
|
|
|
|
|
|
|
|
// Overall Progress Text
|
|
|
|
QRect overallProgressRect;
|
2016-01-21 11:56:01 +03:00
|
|
|
overallProgressRect.setTop(pBRect.bottom() + margin);
|
|
|
|
overallProgressRect.setHeight(fileNameTextHeight);
|
|
|
|
overallProgressRect.setLeft(pBRect.left());
|
|
|
|
overallProgressRect.setWidth(pBRect.width());
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->setFont(progressFont);
|
|
|
|
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, overallProgressRect),
|
2016-01-21 11:56:01 +03:00
|
|
|
Qt::AlignLeft | Qt::AlignVCenter, overallString);
|
2015-07-06 15:44:53 +03:00
|
|
|
// painter->drawRect(overallProgressRect);
|
|
|
|
|
|
|
|
painter->restore();
|
|
|
|
}
|
2015-06-15 15:16:21 +03:00
|
|
|
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->restore();
|
2015-08-13 13:33:20 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
QStyleOptionToolButton btnOpt;
|
|
|
|
btnOpt.state = option.state;
|
|
|
|
btnOpt.state &= ~(QStyle::State_Selected | QStyle::State_HasFocus);
|
|
|
|
btnOpt.state |= QStyle::State_Raised;
|
2015-08-13 15:11:13 +03:00
|
|
|
btnOpt.arrowType = Qt::NoArrow;
|
|
|
|
btnOpt.subControls = QStyle::SC_ToolButton;
|
2016-01-13 13:57:15 +03:00
|
|
|
btnOpt.rect = optionsButtonVisualRect;
|
2019-12-19 21:50:21 +03:00
|
|
|
btnOpt.icon = _iconMore;
|
2018-04-19 11:27:37 +03:00
|
|
|
int e = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
|
|
|
|
btnOpt.iconSize = QSize(e,e);
|
2015-08-13 13:33:20 +03:00
|
|
|
QApplication::style()->drawComplexControl(QStyle::CC_ToolButton, &btnOpt, painter);
|
|
|
|
}
|
2015-06-15 15:16:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FolderStatusDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|
|
|
const QStyleOptionViewItem &option, const QModelIndex &index)
|
|
|
|
{
|
2018-10-30 22:35:35 +03:00
|
|
|
switch (event->type()) {
|
|
|
|
case QEvent::MouseButtonPress:
|
|
|
|
case QEvent::MouseMove:
|
2020-05-18 21:54:23 +03:00
|
|
|
if (const auto *view = qobject_cast<const QAbstractItemView *>(option.widget)) {
|
|
|
|
auto *me = static_cast<QMouseEvent *>(event);
|
2018-10-30 22:35:35 +03:00
|
|
|
QModelIndex index;
|
|
|
|
if (me->buttons()) {
|
|
|
|
index = view->indexAt(me->pos());
|
|
|
|
}
|
|
|
|
if (_pressedIndex != index) {
|
|
|
|
_pressedIndex = index;
|
|
|
|
view->viewport()->update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QEvent::MouseButtonRelease:
|
|
|
|
_pressedIndex = QModelIndex();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2015-06-15 15:16:21 +03:00
|
|
|
return QStyledItemDelegate::editorEvent(event, model, option, index);
|
|
|
|
}
|
|
|
|
|
2016-01-13 13:42:49 +03:00
|
|
|
QRect FolderStatusDelegate::optionsButtonRect(QRect within, Qt::LayoutDirection direction)
|
2015-08-13 13:33:20 +03:00
|
|
|
{
|
2016-01-13 13:42:49 +03:00
|
|
|
QFont font = QFont();
|
|
|
|
QFont aliasFont = makeAliasFont(font);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
within.setHeight(FolderStatusDelegate::rootFolderHeightWithoutErrors(fm, aliasFm));
|
|
|
|
|
2015-08-13 13:33:20 +03:00
|
|
|
QStyleOptionToolButton opt;
|
2018-04-19 11:27:37 +03:00
|
|
|
int e = QApplication::style()->pixelMetric(QStyle::PM_ButtonIconSize);
|
|
|
|
opt.rect.setSize(QSize(e,e));
|
|
|
|
QSize size = QApplication::style()->sizeFromContents(QStyle::CT_ToolButton, &opt, opt.rect.size()).expandedTo(QApplication::globalStrut());
|
2015-08-13 13:33:20 +03:00
|
|
|
|
|
|
|
int margin = QApplication::style()->pixelMetric(QStyle::PM_DefaultLayoutSpacing);
|
2016-01-07 15:37:46 +03:00
|
|
|
QRect r(QPoint(within.right() - size.width() - margin,
|
|
|
|
within.top() + within.height() / 2 - size.height() / 2),
|
|
|
|
size);
|
|
|
|
return QStyle::visualRect(direction, within, r);
|
2015-08-13 13:33:20 +03:00
|
|
|
}
|
|
|
|
|
2018-10-30 22:35:35 +03:00
|
|
|
QRect FolderStatusDelegate::addButtonRect(QRect within, Qt::LayoutDirection direction)
|
|
|
|
{
|
|
|
|
QFontMetrics fm(qApp->font("QPushButton"));
|
|
|
|
QStyleOptionButton opt;
|
|
|
|
opt.text = addFolderText();
|
|
|
|
QSize size = QApplication::style()->sizeFromContents(QStyle::CT_PushButton, &opt, fm.size(Qt::TextSingleLine, opt.text)).expandedTo(QApplication::globalStrut());
|
|
|
|
QRect r(QPoint(within.left(), within.top() + within.height() / 2 - size.height() / 2), size);
|
|
|
|
return QStyle::visualRect(direction, within, r);
|
|
|
|
}
|
|
|
|
|
2017-07-04 15:08:41 +03:00
|
|
|
QRect FolderStatusDelegate::errorsListRect(QRect within)
|
|
|
|
{
|
|
|
|
QFont font = QFont();
|
|
|
|
QFont aliasFont = makeAliasFont(font);
|
|
|
|
QFontMetrics fm(font);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
within.setTop(within.top() + FolderStatusDelegate::rootFolderHeightWithoutErrors(fm, aliasFm));
|
|
|
|
return within;
|
|
|
|
}
|
|
|
|
|
2019-12-19 21:50:21 +03:00
|
|
|
void FolderStatusDelegate::slotStyleChanged()
|
|
|
|
{
|
|
|
|
customizeStyle();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FolderStatusDelegate::customizeStyle()
|
|
|
|
{
|
2020-01-18 19:47:17 +03:00
|
|
|
_iconMore = Theme::createColorAwareIcon(QLatin1String(":/client/theme/more.svg"));
|
2019-12-19 21:50:21 +03:00
|
|
|
}
|
2015-08-13 13:33:20 +03:00
|
|
|
|
2015-06-15 15:16:21 +03:00
|
|
|
} // namespace OCC
|