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.
|
||||
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.
|
||||
static QString stripTags(QString text);
|
||||
|
||||
|
|
|
@ -24,13 +24,12 @@ StatusBar::StatusBar(QWidget *parent) : QStatusBar(parent) {
|
|||
m_progressBar->setVisible(false);
|
||||
|
||||
m_progressLabel = new QLabel(this);
|
||||
m_progressLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
m_progressLabel->setText("aaa");
|
||||
m_progressLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
m_progressLabel->setVisible(false);
|
||||
|
||||
// Add widgets.
|
||||
addPermanentWidget(m_progressLabel);
|
||||
addPermanentWidget(m_progressBar);
|
||||
addWidget(m_progressBar);
|
||||
addWidget(m_progressLabel);
|
||||
addPermanentWidget(m_fullscreenSwitcher);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,9 +36,14 @@ QPointer<SystemTrayIcon> SystemTrayIcon::s_trayIcon;
|
|||
SystemTrayIcon::SystemTrayIcon(const QString &normal_icon,
|
||||
const QString &plain_icon,
|
||||
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.");
|
||||
|
||||
m_font.setBold(true);
|
||||
|
||||
// Initialize icon.
|
||||
setNumber();
|
||||
setContextMenu(parent->getTrayMenu());
|
||||
|
@ -121,45 +126,46 @@ void SystemTrayIcon::show() {
|
|||
#endif
|
||||
}
|
||||
|
||||
// TODO: Set better colors for number -> better readability.
|
||||
void SystemTrayIcon::setNumber(int number) {
|
||||
if (number <= 0) {
|
||||
QSystemTrayIcon::setIcon(QIcon(m_normalIcon));
|
||||
}
|
||||
else {
|
||||
QPixmap background = QPixmap(APP_ICON_PLAIN_PATH);
|
||||
QPainter trayPainter;
|
||||
QFont font = QFont();
|
||||
QPixmap background(m_plainPixmap);
|
||||
QPainter tray_painter;
|
||||
|
||||
font.setBold(true);
|
||||
trayPainter.begin(&background);
|
||||
trayPainter.setBrush(Qt::black);
|
||||
tray_painter.begin(&background);
|
||||
tray_painter.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
|
||||
// infinity symbol in that case.
|
||||
if (number > 99) {
|
||||
font.setPixelSize(90);
|
||||
trayPainter.setFont(font);
|
||||
trayPainter.drawText(QRect(0, 0, 128, 128),
|
||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||
"∞");
|
||||
m_font.setPixelSize(100);
|
||||
|
||||
tray_painter.setFont(m_font);
|
||||
tray_painter.drawText(QRect(0, 0, 128, 128),
|
||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||
QChar(8734));
|
||||
}
|
||||
else {
|
||||
// Smaller number if it has 2 digits.
|
||||
if (number > 9) {
|
||||
font.setPixelSize(70);
|
||||
m_font.setPixelSize(80);
|
||||
}
|
||||
// Bigger number if it has just one digit.
|
||||
else {
|
||||
font.setPixelSize(90);
|
||||
m_font.setPixelSize(100);
|
||||
}
|
||||
|
||||
trayPainter.setFont(font);
|
||||
trayPainter.drawText(QRect(0, 0, 128, 128),
|
||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||
QString::number(number));
|
||||
tray_painter.setFont(m_font);
|
||||
tray_painter.drawText(QRect(0, 0, 128, 128),
|
||||
Qt::AlignVCenter | Qt::AlignCenter ,
|
||||
QString::number(number));
|
||||
}
|
||||
trayPainter.end();
|
||||
tray_painter.end();
|
||||
|
||||
QSystemTrayIcon::setIcon(QIcon(background));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QSystemTrayIcon>
|
||||
#include <QPointer>
|
||||
#include <QPixmap>
|
||||
#include <QMenu>
|
||||
|
||||
|
||||
|
@ -22,7 +23,7 @@ class TrayIconMenu : public QMenu {
|
|||
#endif
|
||||
|
||||
class SystemTrayIcon : public QSystemTrayIcon {
|
||||
Q_OBJECT
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
// Constructors and destructors.
|
||||
|
@ -56,8 +57,9 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
|||
void onActivated(const QSystemTrayIcon::ActivationReason &reason);
|
||||
|
||||
private:
|
||||
QString m_normalIcon;
|
||||
QString m_plainIcon;
|
||||
QIcon m_normalIcon;
|
||||
QPixmap m_plainPixmap;
|
||||
QFont m_font;
|
||||
|
||||
static QPointer<SystemTrayIcon> s_trayIcon;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue