{
InteropHelper::initialize ();
+ Application::setAttribute (Qt::AA_EnableHighDpiScaling);
+ Application::setAttribute (Qt::AA_UseHighDpiPixmaps);
+
Application app (argc, argv);
return app.exec ();
}
SessionDialog.cc
SqueezeLabel.cc
StatsDialog.cc
+ StyleHelper.cc
Torrent.cc
TorrentDelegate.cc
TorrentDelegateMin.cc
Speed.h
SqueezeLabel.h
StatsDialog.h
+ StyleHelper.h
Torrent.h
TorrentDelegate.h
TorrentDelegateMin.h
{
ensureCacheDirHasBeenScanned ();
- const QPixmap pixmap = myPixmaps[host];
- const QSize rightSize = getIconSize ();
- return pixmap.isNull () || pixmap.size () == rightSize ? pixmap : pixmap.scaled (rightSize);
+ return myPixmaps[host];
}
void
const int count = torrentsPerHost[name];
row->setData (count, FilterBarComboBox::CountRole);
row->setData (getCountString (count), FilterBarComboBox::CountStringRole);
- row->setData (favicons.findFromHost (host), Qt::DecorationRole);
+ row->setData (QIcon (favicons.findFromHost (host)), Qt::DecorationRole);
}
// rows to remove
const int count = torrentsPerHost[host];
row->setData (count, FilterBarComboBox::CountRole);
row->setData (getCountString (count), FilterBarComboBox::CountStringRole);
- row->setData (favicons.findFromHost (host), Qt::DecorationRole);
+ row->setData (QIcon (favicons.findFromHost (host)), Qt::DecorationRole);
row->setData (host, TrackerRole);
myTrackerModel->insertRow (i, row);
anyAdded = true;
#include <QStylePainter>
#include "FilterBarComboBox.h"
+#include "StyleHelper.h"
#include "Utils.h"
namespace
rect.adjust (2, 1, -2, -1);
// draw the icon
- QPixmap pixmap;
- QVariant variant = modelIndex.data (Qt::DecorationRole);
- switch (variant.type ())
- {
- case QVariant::Pixmap: pixmap = qvariant_cast<QPixmap> (variant); break;
- case QVariant::Icon: pixmap = qvariant_cast<QIcon> (variant).pixmap (iconSize ()); break;
- default: break;
- }
- if (!pixmap.isNull ())
+ const QIcon icon = Utils::getIconFromIndex (modelIndex);
+ if (!icon.isNull ())
{
const QRect iconRect = QStyle::alignedRect(opt.direction, Qt::AlignLeft | Qt::AlignVCenter,
opt.iconSize, rect);
- painter.drawPixmap (iconRect.topLeft (), pixmap);
+ icon.paint (&painter, iconRect, Qt::AlignCenter, StyleHelper::getIconMode (opt.state), QIcon::Off);
Utils::narrowRect (rect, iconRect.width () + hmargin, 0, opt.direction);
}
#include "FilterBarComboBox.h"
#include "FilterBarComboBoxDelegate.h"
+#include "StyleHelper.h"
#include "Utils.h"
namespace
Utils::narrowRect (boundingBox, 0, countRect.width () + hmargin, option.direction);
const QRect displayRect = boundingBox;
+ const QIcon icon = Utils::getIconFromIndex (index);
+
drawBackground (painter, option, index);
- QStyleOptionViewItem option2 = option;
- option2.decorationSize = myCombo->iconSize ();
- drawDecoration (painter, option, decorationRect, decoration (option2,index.data (Qt::DecorationRole)));
+ icon.paint (painter, decorationRect, Qt::AlignCenter, StyleHelper::getIconMode (option.state), QIcon::Off);
drawDisplay (painter, option, displayRect, index.data (Qt::DisplayRole).toString ());
drawDisplay (painter, disabledOption, countRect, index.data (FilterBarComboBox::CountStringRole).toString ());
drawFocus (painter, option, displayRect|countRect);
QSize size = QItemDelegate::sizeHint (option, index);
size.setHeight (qMax (size.height (), myCombo->iconSize ().height () + 6));
size.rwidth () += s->pixelMetric (QStyle::PM_FocusFrameHMargin, 0, myCombo);
- size.rwidth () += rect (option,index,FilterBarComboBox::CountStringRole).width ();
+ size.rwidth () += rect (option, index, FilterBarComboBox::CountStringRole).width ();
size.rwidth () += hmargin * 4;
return size;
}
--- /dev/null
+/*
+ * This file Copyright (C) 2017 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ */
+
+#include "StyleHelper.h"
+
+QIcon::Mode
+StyleHelper::getIconMode (QStyle::State state)
+{
+ if ((state & QStyle::State_Enabled) == 0)
+ return QIcon::Disabled;
+ if ((state & QStyle::State_Selected) != 0)
+ return QIcon::Selected;
+ return QIcon::Normal;
+}
--- /dev/null
+/*
+ * This file Copyright (C) 2017 Mnemosyne LLC
+ *
+ * It may be used under the GNU GPL versions 2 or 3
+ * or any future license endorsed by Mnemosyne LLC.
+ *
+ */
+
+#pragma once
+
+#include <QIcon>
+#include <QStyle>
+
+class StyleHelper
+{
+ public:
+ static QIcon::Mode getIconMode (QStyle::State state);
+};
break;
case Qt::DecorationRole:
- var = trackerInfo.st.getFavicon ();
+ var = QIcon (trackerInfo.st.getFavicon ());
break;
case TrackerRole:
return fallback;
}
+QIcon
+Utils::getIconFromIndex (const QModelIndex& index)
+{
+ const QVariant variant = index.data (Qt::DecorationRole);
+ switch (variant.type ())
+ {
+ case QVariant::Icon:
+ return qvariant_cast<QIcon> (variant);
+
+ case QVariant::Pixmap:
+ return QIcon (qvariant_cast<QPixmap> (variant));
+
+ default:
+ return QIcon ();
+ }
+}
+
bool
Utils::isValidUtf8 (const char * s)
{
class QColor;
class QHeaderView;
class QIcon;
+class QModelIndex;
class Utils
{
public:
static QIcon guessMimeIcon (const QString& filename);
+ static QIcon getIconFromIndex (const QModelIndex& index);
+
// Test if string is UTF-8 or not
static bool isValidUtf8 (const char * s);
SessionDialog.cc \
SqueezeLabel.cc \
StatsDialog.cc \
+ StyleHelper.cc \
Torrent.cc \
TorrentDelegate.cc \
TorrentDelegateMin.cc \