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);
|
2017-05-17 11:55:42 +03:00
|
|
|
aliasFont.setPointSize(normalFont.pointSize() + 2);
|
2016-01-13 13:42:49 +03:00
|
|
|
return aliasFont;
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:16:21 +03:00
|
|
|
namespace OCC {
|
|
|
|
|
2017-05-17 11:55:42 +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.
|
2017-05-17 11:55:42 +03:00
|
|
|
QSize FolderStatusDelegate::sizeHint(const QStyleOptionViewItem &option,
|
|
|
|
const QModelIndex &index) const
|
2015-06-15 15:16:21 +03:00
|
|
|
{
|
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) {
|
2017-05-17 11:55:42 +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;
|
2017-05-17 11:55:42 +03:00
|
|
|
static_cast<QStyleOption &>(opt) = option;
|
2015-07-06 16:41:38 +03:00
|
|
|
opt.text = addFolderText();
|
|
|
|
return QApplication::style()->sizeFromContents(
|
2017-05-17 11:55:42 +03:00
|
|
|
QStyle::CT_PushButton, &opt, fm.size(Qt::TextSingleLine, opt.text))
|
|
|
|
.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
|
|
|
|
2018-08-18 10:37:00 +03:00
|
|
|
// add some space for the message boxes.
|
2017-07-12 15:50:51 +03:00
|
|
|
int margin = fm.height() / 4;
|
2018-08-18 10:37:00 +03:00
|
|
|
for (auto role : {FolderConflictMsg, FolderErrorMsg, FolderInfoMsg}) {
|
|
|
|
auto msgs = qvariant_cast<QStringList>(index.data(role));
|
|
|
|
if (!msgs.isEmpty()) {
|
|
|
|
h += margin + 2 * margin + msgs.count() * fm.height();
|
|
|
|
}
|
2016-01-13 13:42:49 +03:00
|
|
|
}
|
|
|
|
|
2020-05-27 15:36:07 +03:00
|
|
|
return {0, h};
|
2016-01-13 13:42:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int FolderStatusDelegate::rootFolderHeightWithoutErrors(const QFontMetrics &fm, const QFontMetrics &aliasFm)
|
|
|
|
{
|
2017-05-17 11:55:42 +03:00
|
|
|
const int aliasMargin = aliasFm.height() / 2;
|
|
|
|
const int margin = fm.height() / 4;
|
|
|
|
|
|
|
|
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,
|
2017-05-17 11:55:42 +03:00
|
|
|
const QModelIndex &index) const
|
2015-06-15 15:16:21 +03:00
|
|
|
{
|
2018-10-30 22:35:35 +03:00
|
|
|
if (index.data(AddButton).toBool()) {
|
|
|
|
const_cast<QStyleOptionViewItem &>(option).showDecorationSelected = false;
|
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QStyledItemDelegate::paint(painter, option, index);
|
2015-07-06 16:41:38 +03:00
|
|
|
|
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);
|
2017-05-17 11:55:42 +03:00
|
|
|
QFont subFont = option.font;
|
2015-08-20 14:25:19 +03:00
|
|
|
QFont errorFont = subFont;
|
|
|
|
QFont progressFont = subFont;
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
progressFont.setPointSize(subFont.pointSize() - 2);
|
2015-08-20 14:25:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QFontMetrics subFm(subFont);
|
|
|
|
QFontMetrics aliasFm(aliasFont);
|
|
|
|
QFontMetrics progressFm(progressFont);
|
2015-08-20 14:25:19 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
int aliasMargin = aliasFm.height() / 2;
|
|
|
|
int margin = subFm.height() / 4;
|
2015-08-20 14:25:19 +03:00
|
|
|
|
2015-07-14 12:03:25 +03:00
|
|
|
if (index.data(AddButton).toBool()) {
|
2015-07-06 16:41:38 +03:00
|
|
|
QStyleOptionButton opt;
|
2017-05-17 11:55:42 +03:00
|
|
|
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();
|
|
|
|
|
2020-07-07 10:39:27 +03:00
|
|
|
auto statusIcon = qvariant_cast<QIcon>(index.data(FolderStatusIconRole));
|
|
|
|
auto aliasText = qvariant_cast<QString>(index.data(HeaderRole));
|
|
|
|
auto pathText = qvariant_cast<QString>(index.data(FolderPathRole));
|
|
|
|
auto remotePath = qvariant_cast<QString>(index.data(FolderSecondPathRole));
|
|
|
|
auto conflictTexts = qvariant_cast<QStringList>(index.data(FolderConflictMsg));
|
|
|
|
auto errorTexts = qvariant_cast<QStringList>(index.data(FolderErrorMsg));
|
2018-08-18 10:37:00 +03:00
|
|
|
auto infoTexts = qvariant_cast<QStringList>(index.data(FolderInfoMsg));
|
2020-07-07 10:39:27 +03:00
|
|
|
|
|
|
|
auto overallPercent = qvariant_cast<int>(index.data(SyncProgressOverallPercent));
|
|
|
|
auto overallString = qvariant_cast<QString>(index.data(SyncProgressOverallString));
|
|
|
|
auto itemString = qvariant_cast<QString>(index.data(SyncProgressItemString));
|
|
|
|
auto warningCount = qvariant_cast<int>(index.data(WarningCount));
|
|
|
|
auto syncOngoing = qvariant_cast<bool>(index.data(SyncRunning));
|
|
|
|
auto syncDate = qvariant_cast<QDateTime>(index.data(SyncDate));
|
|
|
|
auto syncEnabled = qvariant_cast<bool>(index.data(FolderAccountConnected));
|
|
|
|
|
|
|
|
auto iconRect = option.rect;
|
|
|
|
auto aliasRect = option.rect;
|
2015-07-06 15:44:53 +03:00
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
iconRect.setLeft(option.rect.left() + aliasMargin);
|
|
|
|
iconRect.setTop(iconRect.top() + aliasMargin); // (iconRect.height()-iconsize.height())/2);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
// alias box
|
2017-05-17 11:55:42 +03:00
|
|
|
aliasRect.setTop(aliasRect.top() + aliasMargin);
|
2015-07-06 15:44:53 +03:00
|
|
|
aliasRect.setBottom(aliasRect.top() + aliasFm.height());
|
2017-05-17 11:55:42 +03:00
|
|
|
aliasRect.setRight(aliasRect.right() - aliasMargin);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
// remote directory box
|
2020-07-07 10:39:27 +03:00
|
|
|
auto remotePathRect = aliasRect;
|
2017-05-17 11:55:42 +03:00
|
|
|
remotePathRect.setTop(aliasRect.bottom() + margin);
|
2015-07-06 15:44:53 +03:00
|
|
|
remotePathRect.setBottom(remotePathRect.top() + subFm.height());
|
|
|
|
|
|
|
|
// local directory box
|
2020-07-07 10:39:27 +03:00
|
|
|
auto localPathRect = remotePathRect;
|
2017-05-17 11:55:42 +03:00
|
|
|
localPathRect.setTop(remotePathRect.bottom() + margin);
|
|
|
|
localPathRect.setBottom(localPathRect.top() + subFm.height());
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
iconRect.setBottom(localPathRect.bottom());
|
|
|
|
iconRect.setWidth(iconRect.height());
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
int nextToIcon = iconRect.right() + aliasMargin;
|
2015-07-06 15:44:53 +03:00
|
|
|
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);
|
|
|
|
|
2017-05-17 11:55:42 +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(),
|
2017-05-17 11:55:42 +03:00
|
|
|
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.
|
2017-05-17 11:55:42 +03:00
|
|
|
if (warningCount > 0 && syncOngoing) {
|
2015-07-06 15:44:53 +03:00
|
|
|
QRect warnRect;
|
|
|
|
warnRect.setLeft(iconRect.left());
|
2017-05-17 11:55:42 +03:00
|
|
|
warnRect.setTop(iconRect.bottom() - 17);
|
2015-07-06 15:44:53 +03:00
|
|
|
warnRect.setWidth(16);
|
|
|
|
warnRect.setHeight(16);
|
|
|
|
|
2020-01-18 19:47:17 +03:00
|
|
|
QIcon warnIcon(":/client/theme/warning");
|
2017-05-17 11:55:42 +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);
|
2017-05-17 11:55:42 +03:00
|
|
|
painter->drawPixmap(QPoint(warnRect.left(), warnRect.top()), pm);
|
2015-07-06 15:44:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
2017-05-17 11:55:42 +03:00
|
|
|
? QPalette::Normal
|
|
|
|
: QPalette::Disabled;
|
2015-07-06 15:44:53 +03:00
|
|
|
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();
|
2017-05-17 11:55:42 +03:00
|
|
|
if (!showProgess) {
|
2015-10-27 14:52:33 +03:00
|
|
|
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)),
|
2017-05-17 11:55:42 +03:00
|
|
|
Qt::ElideRight, remotePathRect.width());
|
2016-01-07 15:37:46 +03:00
|
|
|
painter->drawText(QStyle::visualRect(option.direction, option.rect, remotePathRect),
|
2017-05-17 11:55:42 +03:00
|
|
|
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),
|
2017-05-17 11:55:42 +03:00
|
|
|
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);
|
2017-05-17 11:55:42 +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),
|
2017-05-17 11:55:42 +03:00
|
|
|
4, 4);
|
|
|
|
painter->setPen(Qt::white);
|
2015-07-06 15:44:53 +03:00
|
|
|
painter->setFont(errorFont);
|
2017-07-12 15:50:51 +03:00
|
|
|
QRect textRect(rect.left() + margin,
|
|
|
|
rect.top() + margin,
|
|
|
|
rect.width() - 2 * margin,
|
2017-05-17 11:55:42 +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));
|
2018-08-18 10:37:00 +03:00
|
|
|
if (!infoTexts.isEmpty())
|
|
|
|
drawTextBox(infoTexts, QColor(0x4d, 0xba, 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;
|
2017-05-17 11:55:42 +03:00
|
|
|
pBRect.setTop(remotePathRect.top());
|
|
|
|
pBRect.setLeft(nextToIcon);
|
2015-07-06 15:44:53 +03:00
|
|
|
pBRect.setHeight(barHeight);
|
2017-05-17 11:55:42 +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
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
pBarOpt.state = option.state | QStyle::State_Horizontal;
|
|
|
|
pBarOpt.minimum = 0;
|
|
|
|
pBarOpt.maximum = 100;
|
2015-07-06 15:44:53 +03:00
|
|
|
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
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &pBarOpt, painter);
|
2015-07-06 15:44:53 +03:00
|
|
|
|
|
|
|
// Overall Progress Text
|
|
|
|
QRect overallProgressRect;
|
2017-05-17 11:55:42 +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),
|
2017-05-17 11:55:42 +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);
|
2017-05-17 11:55:42 +03:00
|
|
|
QApplication::style()->drawComplexControl(QStyle::CC_ToolButton, &btnOpt, painter);
|
2015-08-13 13:33:20 +03:00
|
|
|
}
|
2015-06-15 15:16:21 +03:00
|
|
|
}
|
|
|
|
|
2017-05-17 11:55:42 +03:00
|
|
|
bool FolderStatusDelegate::editorEvent(QEvent *event, QAbstractItemModel *model,
|
|
|
|
const QStyleOptionViewItem &option, const QModelIndex &index)
|
2015-06-15 15:16:21 +03:00
|
|
|
{
|
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,
|
2017-05-17 11:55:42 +03:00
|
|
|
within.top() + within.height() / 2 - size.height() / 2),
|
|
|
|
size);
|
2016-01-07 15:37:46 +03:00
|
|
|
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
|