diff --git a/CMakeLists.txt b/CMakeLists.txt index bd3885956..988586f1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -276,8 +276,12 @@ if(WIN32) RUNTIME DESTINATION ./) install(DIRECTORY resources/graphics/themes/mini-oxygen DESTINATION ./themes) - install(FILES resources/graphics/${APP_LOW_NAME}.png - DESTINATION ./) + install(FILES resources/graphics/${APP_LOW_NAME}_128.png + DESTINATION ./ + RENAME ${APP_LOW_NAME}.png) + install(FILES resources/graphics/${APP_LOW_NAME}_plain_128.png + DESTINATION ./ + RENAME ${APP_LOW_NAME}_plain.png) install(FILES ${APP_QM} DESTINATION ./l10n) install(FILES ${APP_MISC} @@ -290,8 +294,12 @@ elseif(UNIX) DESTINATION share/${APP_LOW_NAME}/themes) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/resources/desktop/${APP_LOW_NAME}.desktop DESTINATION share/applications) - install(FILES resources/graphics/${APP_LOW_NAME}.png - DESTINATION share/icons/hicolor/256x256/apps/) + install(FILES resources/graphics/${APP_LOW_NAME}_128.png + DESTINATION share/icons/hicolor/128x128/apps/ + RENAME ${APP_LOW_NAME}.png) + install(FILES resources/graphics/${APP_LOW_NAME}_plain_128.png + DESTINATION share/icons/hicolor/128x128/apps/ + RENAME ${APP_LOW_NAME}_plain.png) install(FILES ${APP_QM} DESTINATION share/${APP_LOW_NAME}/l10n) install(FILES ${APP_MISC} diff --git a/resources/graphics/rssguard_128.png b/resources/graphics/rssguard_128.png new file mode 100644 index 000000000..7cce76018 Binary files /dev/null and b/resources/graphics/rssguard_128.png differ diff --git a/resources/graphics/rssguard_22.png b/resources/graphics/rssguard_22.png new file mode 100644 index 000000000..7722fcd88 Binary files /dev/null and b/resources/graphics/rssguard_22.png differ diff --git a/resources/graphics/rssguard_256.png b/resources/graphics/rssguard_256.png new file mode 100644 index 000000000..55dfb253a Binary files /dev/null and b/resources/graphics/rssguard_256.png differ diff --git a/resources/graphics/rssguard_48.png b/resources/graphics/rssguard_48.png new file mode 100644 index 000000000..3a4ee310f Binary files /dev/null and b/resources/graphics/rssguard_48.png differ diff --git a/resources/graphics/rssguard.png b/resources/graphics/rssguard_512.png similarity index 100% rename from resources/graphics/rssguard.png rename to resources/graphics/rssguard_512.png diff --git a/resources/graphics/rssguard_64.png b/resources/graphics/rssguard_64.png new file mode 100644 index 000000000..99e3bab2b Binary files /dev/null and b/resources/graphics/rssguard_64.png differ diff --git a/resources/graphics/rssguard_plain_128.png b/resources/graphics/rssguard_plain_128.png new file mode 100644 index 000000000..d1c62ad67 Binary files /dev/null and b/resources/graphics/rssguard_plain_128.png differ diff --git a/src/core/defs.h.in b/src/core/defs.h.in index 570027d49..346443814 100644 --- a/src/core/defs.h.in +++ b/src/core/defs.h.in @@ -29,13 +29,15 @@ #define APP_SKIN_PATH APP_PREFIX + QString("/share/rssguard/skins") #define APP_INFO_PATH APP_PREFIX + QString("/share/rssguard/information") #define APP_THEME_PATH APP_PREFIX + QString("/share/rssguard/themes") -#define APP_ICON_PATH APP_PREFIX + QString("/share/icons/hicolor/256x256/apps/rssguard.png") +#define APP_ICON_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@.png") +#define APP_ICON_PLAIN_PATH APP_PREFIX + QString("/share/icons/hicolor/128x128/apps/@APP_LOW_NAME@_plain.png") #elif defined(Q_OS_WIN) #define APP_LANG_PATH QApplication::applicationDirPath() + QString("/l10n") #define APP_SKIN_PATH QApplication::applicationDirPath() + QString("/skins") #define APP_INFO_PATH QApplication::applicationDirPath() #define APP_THEME_PATH QApplication::applicationDirPath() + QString("/themes") -#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/rssguard.png") +#define APP_ICON_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@.png") +#define APP_ICON_PLAIN_PATH QApplication::applicationDirPath() + QString("/@APP_LOW_NAME@_plain.png") #endif #endif // DEFS_H diff --git a/src/gui/formmain.cpp b/src/gui/formmain.cpp index fa022134c..1315a2f5b 100644 --- a/src/gui/formmain.cpp +++ b/src/gui/formmain.cpp @@ -24,7 +24,6 @@ FormMain::FormMain(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::FormMain // testing purposes SystemTrayIcon *icon = SystemTrayIcon::getInstance(); - icon->setIcon(QIcon(APP_ICON_PATH)); icon->show(); } diff --git a/src/gui/systemtrayicon.cpp b/src/gui/systemtrayicon.cpp index 648322357..e2808ad9b 100644 --- a/src/gui/systemtrayicon.cpp +++ b/src/gui/systemtrayicon.cpp @@ -1,3 +1,5 @@ +#include + #include "gui/systemtrayicon.h" #include "gui/formmain.h" #include "core/settings.h" @@ -6,8 +8,14 @@ QPointer SystemTrayIcon::m_trayIcon; -SystemTrayIcon::SystemTrayIcon(QObject *parent) : QSystemTrayIcon(parent) { +SystemTrayIcon::SystemTrayIcon(const QString &normal_icon, + const QString &plain_icon, + QObject *parent) + : QSystemTrayIcon(parent), m_normalIcon(normal_icon), m_plainIcon(plain_icon) { qDebug("Creating SystemTrayIcon instance."); + + // Initialize icon. + setNumber(); } SystemTrayIcon::~SystemTrayIcon() { @@ -26,9 +34,54 @@ bool SystemTrayIcon::isSystemTrayActivated() { SystemTrayIcon *SystemTrayIcon::getInstance() { if (m_trayIcon.isNull()) { - m_trayIcon = new SystemTrayIcon(FormMain::getInstance()); + m_trayIcon = new SystemTrayIcon(APP_ICON_PATH, + APP_ICON_PLAIN_PATH, + FormMain::getInstance()); } return m_trayIcon; } +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(); + + font.setBold(true); + trayPainter.begin(&background); + trayPainter.setPen(Qt::black); + + // 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 , + "∞"); + } + else { + // Smaller number if it has 2 digits. + if (number > 9) { + font.setPixelSize(70); + } + // Bigger number if it has just one digit. + else { + font.setPixelSize(90); + } + + trayPainter.setFont(font); + trayPainter.drawText(QRect(0, 0, 128, 128), + Qt::AlignVCenter | Qt::AlignCenter , + QString::number(number)); + } + + trayPainter.end(); + + QSystemTrayIcon::setIcon(QIcon(background)); + } +} diff --git a/src/gui/systemtrayicon.h b/src/gui/systemtrayicon.h index d0096e398..33d7a2a4f 100644 --- a/src/gui/systemtrayicon.h +++ b/src/gui/systemtrayicon.h @@ -8,7 +8,9 @@ class SystemTrayIcon : public QSystemTrayIcon { Q_OBJECT public: - explicit SystemTrayIcon(QObject *parent = 0); + explicit SystemTrayIcon(const QString &normal_icon, + const QString &plain_icon, + QObject *parent = 0); ~SystemTrayIcon(); // Returns true if tray icon CAN be constructed on this machine. @@ -22,6 +24,9 @@ class SystemTrayIcon : public QSystemTrayIcon { // WARNING: Use this in cooperation with SystemTrayIcon::isSystemTrayActivated(). static SystemTrayIcon *getInstance(); + // Sets the number to be visible in the tray icon, -1 removes it. + void setNumber(int number = -1); + // TODO: Implement method for manual clearing of the tray icon. Creating of tray icon // handled by getInstance(). signals: @@ -29,6 +34,9 @@ class SystemTrayIcon : public QSystemTrayIcon { public slots: private: + QString m_normalIcon; + QString m_plainIcon; + static QPointer m_trayIcon; }; diff --git a/src/gui/themefactory.cpp b/src/gui/themefactory.cpp index f9eb95b75..eba2673e2 100644 --- a/src/gui/themefactory.cpp +++ b/src/gui/themefactory.cpp @@ -68,6 +68,10 @@ QString ThemeFactory::getCurrentIconTheme() { return current_theme_name; } +QIcon ThemeFactory::fromTheme(const QString &name, const QIcon &fallback) { + return QIcon::fromTheme(name, fallback); +} + void ThemeFactory::setCurrentIconTheme(const QString &theme_name) { Settings::getInstance()->setValue(APP_CFG_GUI, "icon_theme", diff --git a/src/gui/themefactory.h b/src/gui/themefactory.h index b13a91376..a2617c118 100644 --- a/src/gui/themefactory.h +++ b/src/gui/themefactory.h @@ -3,6 +3,7 @@ #include #include +#include class ThemeFactory { @@ -35,6 +36,11 @@ class ThemeFactory { // Sets icon theme with given name as the active one. static void setCurrentIconTheme(const QString &theme_name); + + // Wrapper for QIcon::fromTheme. + // If icon is not found in user-defined icon theme, + // then it is searched in system-default theme (ThemeFactory::getSystemIconTheme()). + static QIcon fromTheme(const QString & name, const QIcon & fallback = QIcon()); }; class ThemeFactoryEvent : public QEvent { diff --git a/src/main.cpp b/src/main.cpp index 716584723..86dcbc14b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,7 +50,7 @@ int main(int argc, char *argv[]) { // This is useful for styles, encoders, ... // This is probably not needed on Windows or Linux, not sure about Mac OS X. #if defined(Q_OS_MAC) - QApplication::addLibraryPath(APP_PLUGIN_PATH); + QtSingleApplication::addLibraryPath(APP_PLUGIN_PATH); #endif // Add an extra path for non-system icon themes. @@ -64,7 +64,7 @@ int main(int argc, char *argv[]) { QtSingleApplication::setApplicationVersion(APP_VERSION); QtSingleApplication::setOrganizationName(APP_AUTHORS); QtSingleApplication::setOrganizationDomain(APP_URL); - QtSingleApplication::setWindowIcon(QIcon(APP_INFO_PATH)); + QtSingleApplication::setWindowIcon(QIcon(APP_ICON_PATH)); // Instantiate main application window. FormMain window;