Work on system icons.
This commit is contained in:
parent
db15474aa3
commit
82d3de2699
4 changed files with 38 additions and 27 deletions
|
@ -24,6 +24,10 @@ class TextFactory {
|
||||||
// NOTE: On Windows UTC is known to be broken.
|
// NOTE: On Windows UTC is known to be broken.
|
||||||
static QDateTime parseDateTime(qint64 milis_from_epoch);
|
static QDateTime parseDateTime(qint64 milis_from_epoch);
|
||||||
|
|
||||||
|
// TODO: ocekovat stripovani tagu a escapovani
|
||||||
|
// http://harmattan-dev.nokia.com/docs/library/html/qt4/qtextdocumentfragment.html
|
||||||
|
// mozna by to bylo lepsi, meotda ::fromHtml
|
||||||
|
|
||||||
// Strips "<....>" (HTML, XML) tags from given text.
|
// Strips "<....>" (HTML, XML) tags from given text.
|
||||||
static QString stripTags(QString text);
|
static QString stripTags(QString text);
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,12 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
|
||||||
m_progressBar->setVisible(false);
|
m_progressBar->setVisible(false);
|
||||||
|
|
||||||
m_progressLabel = new QLabel(this);
|
m_progressLabel = new QLabel(this);
|
||||||
m_progressLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
m_progressLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||||
m_progressLabel->setText("aaa");
|
|
||||||
m_progressLabel->setVisible(false);
|
m_progressLabel->setVisible(false);
|
||||||
|
|
||||||
// Add widgets.
|
// Add widgets.
|
||||||
addPermanentWidget(m_progressLabel);
|
addWidget(m_progressBar);
|
||||||
addPermanentWidget(m_progressBar);
|
addWidget(m_progressLabel);
|
||||||
addPermanentWidget(m_fullscreenSwitcher);
|
addPermanentWidget(m_fullscreenSwitcher);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,9 +36,14 @@ QPointer<SystemTrayIcon> SystemTrayIcon::s_trayIcon;
|
||||||
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
|
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
|
||||||
const QString &plain_icon,
|
const QString &plain_icon,
|
||||||
FormMain *parent)
|
FormMain *parent)
|
||||||
: QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainIcon(plain_icon) {
|
: QSystemTrayIcon(parent),
|
||||||
|
m_normalIcon(normal_icon),
|
||||||
|
m_plainPixmap(plain_icon),
|
||||||
|
m_font(QFont()) {
|
||||||
qDebug("Creating SystemTrayIcon instance.");
|
qDebug("Creating SystemTrayIcon instance.");
|
||||||
|
|
||||||
|
m_font.setBold(true);
|
||||||
|
|
||||||
// Initialize icon.
|
// Initialize icon.
|
||||||
setNumber();
|
setNumber();
|
||||||
setContextMenu(parent->getTrayMenu());
|
setContextMenu(parent->getTrayMenu());
|
||||||
|
@ -121,45 +126,46 @@ void SystemTrayIcon::show() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Set better colors for number -> better readability.
|
|
||||||
void SystemTrayIcon::setNumber(int number) {
|
void SystemTrayIcon::setNumber(int number) {
|
||||||
if (number <= 0) {
|
if (number <= 0) {
|
||||||
QSystemTrayIcon::setIcon(QIcon(m_normalIcon));
|
QSystemTrayIcon::setIcon(QIcon(m_normalIcon));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
QPixmap background = QPixmap(APP_ICON_PLAIN_PATH);
|
QPixmap background(m_plainPixmap);
|
||||||
QPainter trayPainter;
|
QPainter tray_painter;
|
||||||
QFont font = QFont();
|
|
||||||
|
|
||||||
font.setBold(true);
|
tray_painter.begin(&background);
|
||||||
trayPainter.begin(&background);
|
tray_painter.setBrush(Qt::black);
|
||||||
trayPainter.setBrush(Qt::black);
|
tray_painter.setRenderHint(QPainter::SmoothPixmapTransform, true);
|
||||||
|
tray_painter.setRenderHint(QPainter::TextAntialiasing, false);
|
||||||
|
|
||||||
// Numbers with more than 2 digits won't be readable, display
|
// Numbers with more than 2 digits won't be readable, display
|
||||||
// infinity symbol in that case.
|
// infinity symbol in that case.
|
||||||
if (number > 99) {
|
if (number > 99) {
|
||||||
font.setPixelSize(90);
|
m_font.setPixelSize(100);
|
||||||
trayPainter.setFont(font);
|
|
||||||
trayPainter.drawText(QRect(0, 0, 128, 128),
|
tray_painter.setFont(m_font);
|
||||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
tray_painter.drawText(QRect(0, 0, 128, 128),
|
||||||
"∞");
|
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||||
|
QChar(8734));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Smaller number if it has 2 digits.
|
// Smaller number if it has 2 digits.
|
||||||
if (number > 9) {
|
if (number > 9) {
|
||||||
font.setPixelSize(70);
|
m_font.setPixelSize(80);
|
||||||
}
|
}
|
||||||
// Bigger number if it has just one digit.
|
// Bigger number if it has just one digit.
|
||||||
else {
|
else {
|
||||||
font.setPixelSize(90);
|
m_font.setPixelSize(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
trayPainter.setFont(font);
|
tray_painter.setFont(m_font);
|
||||||
trayPainter.drawText(QRect(0, 0, 128, 128),
|
tray_painter.drawText(QRect(0, 0, 128, 128),
|
||||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||||
QString::number(number));
|
QString::number(number));
|
||||||
}
|
}
|
||||||
trayPainter.end();
|
tray_painter.end();
|
||||||
|
|
||||||
QSystemTrayIcon::setIcon(QIcon(background));
|
QSystemTrayIcon::setIcon(QIcon(background));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QSystemTrayIcon>
|
#include <QSystemTrayIcon>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QPixmap>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +23,7 @@ class TrayIconMenu : public QMenu {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class SystemTrayIcon : public QSystemTrayIcon {
|
class SystemTrayIcon : public QSystemTrayIcon {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructors and destructors.
|
// Constructors and destructors.
|
||||||
|
@ -56,8 +57,9 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||||
void onActivated(const QSystemTrayIcon::ActivationReason &reason);
|
void onActivated(const QSystemTrayIcon::ActivationReason &reason);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_normalIcon;
|
QIcon m_normalIcon;
|
||||||
QString m_plainIcon;
|
QPixmap m_plainPixmap;
|
||||||
|
QFont m_font;
|
||||||
|
|
||||||
static QPointer<SystemTrayIcon> s_trayIcon;
|
static QPointer<SystemTrayIcon> s_trayIcon;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue