mirror of
https://github.com/YACReader/yacreader
synced 2025-06-04 01:28:55 -04:00
Add support for minimize and start to tray.
This commit is contained in:
parent
23c597d444
commit
e587f59ddb
@ -221,6 +221,11 @@ SOURCES += comic_flow.cpp \
|
|||||||
SOURCES += ../common/gl/yacreader_flow_gl.cpp
|
SOURCES += ../common/gl/yacreader_flow_gl.cpp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macx {
|
||||||
|
HEADERS += trayhandler.h
|
||||||
|
OBJECTIVE_SOURCES += trayhandler.mm
|
||||||
|
}
|
||||||
|
|
||||||
include(./server/server.pri)
|
include(./server/server.pri)
|
||||||
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
||||||
|
|
||||||
|
@ -86,6 +86,9 @@
|
|||||||
#ifdef Q_OS_WIN
|
#ifdef Q_OS_WIN
|
||||||
#include <shellapi.h>
|
#include <shellapi.h>
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
#include "trayhandler.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
LibraryWindow::LibraryWindow()
|
LibraryWindow::LibraryWindow()
|
||||||
: QMainWindow(), fullscreen(false), previousFilter(""), fetching(false), status(LibraryWindow::Normal), removeError(false)
|
: QMainWindow(), fullscreen(false), previousFilter(""), fetching(false), status(LibraryWindow::Normal), removeError(false)
|
||||||
@ -139,35 +142,41 @@ void LibraryWindow::setupUI()
|
|||||||
}
|
}
|
||||||
/* //disabled until icons are ready and macos native code is done
|
/* //disabled until icons are ready and macos native code is done
|
||||||
trayIcon.setIcon(QApplication::windowIcon());
|
trayIcon.setIcon(QApplication::windowIcon());
|
||||||
trayIcon.show();
|
|
||||||
connect(&trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
|
|
||||||
this, SLOT(trayActivation(QSystemTrayIcon::ActivationReason)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void LibraryWindow::trayActivation(QSystemTrayIcon::ActivationReason reason)
|
|
||||||
{
|
|
||||||
if (reason == QSystemTrayIcon::Trigger)
|
|
||||||
{
|
|
||||||
setWindowState((windowState() & ~Qt::WindowMinimized));
|
|
||||||
show();
|
|
||||||
activateWindow();
|
|
||||||
raise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void LibraryWindow::changeEvent(QEvent *event)
|
|
||||||
{
|
|
||||||
if (event->type() == QEvent::WindowStateChange && isMinimized())
|
|
||||||
{
|
|
||||||
hide();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// TODO: Luis: This is a placeholder. Add MacOS, Windows and maybe a fallback
|
||||||
|
// for other systems here.
|
||||||
|
trayIcon.setIcon(QIcon(":/images/iconLibrary.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(&trayIcon, &QSystemTrayIcon::activated,
|
||||||
|
[=] (QSystemTrayIcon::ActivationReason reason) {
|
||||||
|
if (reason == QSystemTrayIcon::Trigger)
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
OSXShowDockIcon();
|
||||||
|
#endif
|
||||||
|
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
trayIcon.setVisible(settings->value(MINIMIZE_TO_TRAY, true).toBool());
|
||||||
|
}
|
||||||
|
|
||||||
|
void LibraryWindow::changeEvent(QEvent *event)
|
||||||
|
{
|
||||||
|
if (event->type() == QEvent::WindowStateChange && isMinimized() &&
|
||||||
|
trayIcon.isVisible())
|
||||||
|
{
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
OSXHideDockIcon();
|
||||||
|
#endif
|
||||||
|
hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
QMainWindow::changeEvent(event);
|
QMainWindow::changeEvent(event);
|
||||||
}
|
}
|
||||||
}*/
|
|
||||||
|
|
||||||
void LibraryWindow::doLayout()
|
void LibraryWindow::doLayout()
|
||||||
{
|
{
|
||||||
|
@ -385,7 +385,7 @@ public slots:
|
|||||||
void checkMaxNumLibraries();
|
void checkMaxNumLibraries();
|
||||||
void showErrorUpgradingLibrary(const QString &path);
|
void showErrorUpgradingLibrary(const QString &path);
|
||||||
|
|
||||||
//void changeEvent(QEvent *event);
|
void changeEvent(QEvent *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||||
@ -394,9 +394,6 @@ private:
|
|||||||
QSize previousSize;
|
QSize previousSize;
|
||||||
std::future<void> upgradeLibraryFuture;
|
std::future<void> upgradeLibraryFuture;
|
||||||
QSystemTrayIcon trayIcon;
|
QSystemTrayIcon trayIcon;
|
||||||
|
|
||||||
private slots:
|
|
||||||
//void trayActivation(QSystemTrayIcon::ActivationReason reason);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,9 @@
|
|||||||
#include "yacreader_libraries.h"
|
#include "yacreader_libraries.h"
|
||||||
#include "exit_check.h"
|
#include "exit_check.h"
|
||||||
#include "opengl_checker.h"
|
#include "opengl_checker.h"
|
||||||
|
#ifdef Q_OS_MACOS
|
||||||
|
#include "trayhandler.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "QsLog.h"
|
#include "QsLog.h"
|
||||||
#include "QsLogDest.h"
|
#include "QsLogDest.h"
|
||||||
@ -127,9 +130,12 @@ int main(int argc, char **argv)
|
|||||||
app.setApplicationVersion(VERSION);
|
app.setApplicationVersion(VERSION);
|
||||||
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
app.setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||||
|
|
||||||
|
// Set window icon according to Freedesktop icon specification
|
||||||
|
// This is mostly relevant for Linux and other Unix systems
|
||||||
if (QIcon::hasThemeIcon("YACReaderLibrary")) {
|
if (QIcon::hasThemeIcon("YACReaderLibrary")) {
|
||||||
app.setWindowIcon(QIcon::fromTheme("YACReaderLibrary"));
|
app.setWindowIcon(QIcon::fromTheme("YACReaderLibrary"));
|
||||||
}
|
}
|
||||||
|
// TODO: We might want to add a fallback icon here.
|
||||||
|
|
||||||
QString destLog = YACReader::getSettingsPath() + "/yacreaderlibrary.log";
|
QString destLog = YACReader::getSettingsPath() + "/yacreaderlibrary.log";
|
||||||
QDir().mkpath(YACReader::getSettingsPath());
|
QDir().mkpath(YACReader::getSettingsPath());
|
||||||
|
@ -43,6 +43,9 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
|||||||
#ifndef NO_OPENGL
|
#ifndef NO_OPENGL
|
||||||
sw->hide();
|
sw->hide();
|
||||||
#endif
|
#endif
|
||||||
|
// Tray icon settings
|
||||||
|
QGroupBox * trayIconBox = new QGroupBox(tr("Tray icon settings"));
|
||||||
|
QVBoxLayout * trayLayout = new QVBoxLayout();
|
||||||
|
|
||||||
auto apiKeyLayout = new QVBoxLayout();
|
auto apiKeyLayout = new QVBoxLayout();
|
||||||
auto apiKeyButton = new QPushButton(tr("Edit Comic Vine API key"));
|
auto apiKeyButton = new QPushButton(tr("Edit Comic Vine API key"));
|
||||||
@ -115,6 +118,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
|||||||
|
|
||||||
auto generalW = new QWidget;
|
auto generalW = new QWidget;
|
||||||
generalW->setLayout(generalLayout);
|
generalW->setLayout(generalLayout);
|
||||||
|
generalLayout->addWidget(trayIconBox);
|
||||||
generalLayout->addWidget(shortcutsBox);
|
generalLayout->addWidget(shortcutsBox);
|
||||||
generalLayout->addWidget(apiKeyBox);
|
generalLayout->addWidget(apiKeyBox);
|
||||||
generalLayout->addStretch();
|
generalLayout->addStretch();
|
||||||
@ -146,6 +150,10 @@ void OptionsDialog::restoreOptions(QSettings *settings)
|
|||||||
{
|
{
|
||||||
YACReaderOptionsDialog::restoreOptions(settings);
|
YACReaderOptionsDialog::restoreOptions(settings);
|
||||||
|
|
||||||
|
trayIconCheckbox->setChecked(settings->value(MINIMIZE_TO_TRAY, true).toBool());
|
||||||
|
startToTrayCheckbox->setChecked(settings->value(START_TO_TRAY, false).toBool());
|
||||||
|
startToTrayCheckbox->setEnabled(trayIconCheckbox->isChecked());
|
||||||
|
|
||||||
bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool();
|
bool useBackgroundImage = settings->value(USE_BACKGROUND_IMAGE_IN_GRID_VIEW, true).toBool();
|
||||||
|
|
||||||
useBackgroundImageCheck->setChecked(useBackgroundImage);
|
useBackgroundImageCheck->setChecked(useBackgroundImage);
|
||||||
|
@ -25,7 +25,6 @@ private slots:
|
|||||||
void backgroundImageBlurRadiusSliderChanged(int value);
|
void backgroundImageBlurRadiusSliderChanged(int value);
|
||||||
void useCurrentComicCoverCheckClicked(bool checked);
|
void useCurrentComicCoverCheckClicked(bool checked);
|
||||||
void resetToDefaults();
|
void resetToDefaults();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QCheckBox * useBackgroundImageCheck;
|
QCheckBox * useBackgroundImageCheck;
|
||||||
QCheckBox * useCurrentComicCoverCheck;
|
QCheckBox * useCurrentComicCoverCheck;
|
||||||
@ -34,8 +33,6 @@ private:
|
|||||||
QLabel * opacityLabel;
|
QLabel * opacityLabel;
|
||||||
QLabel * blurLabel;
|
QLabel * blurLabel;
|
||||||
QPushButton * resetButton;
|
QPushButton * resetButton;
|
||||||
|
|
||||||
QCheckBox *displayContinueReadingBannerCheck;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
7
YACReaderLibrary/trayhandler.h
Normal file
7
YACReaderLibrary/trayhandler.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef TRAY_HANDLER
|
||||||
|
#define TRAY_HANDLER
|
||||||
|
|
||||||
|
void OSXShowDockIcon();
|
||||||
|
void OSXHideDockIcon();
|
||||||
|
|
||||||
|
#endif
|
11
YACReaderLibrary/trayhandler.mm
Normal file
11
YACReaderLibrary/trayhandler.mm
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#import <AppKit/AppKit.h>
|
||||||
|
#include "trayhandler.h"
|
||||||
|
|
||||||
|
void OSXShowDockIcon()
|
||||||
|
{
|
||||||
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
|
||||||
|
}
|
||||||
|
void OSXHideDockIcon()
|
||||||
|
{
|
||||||
|
[NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory];
|
||||||
|
}
|
@ -17,6 +17,8 @@
|
|||||||
#define FULLSCREEN "FULLSCREEN"
|
#define FULLSCREEN "FULLSCREEN"
|
||||||
#define Y_WINDOW_GEOMETRY "GEOMETRY"
|
#define Y_WINDOW_GEOMETRY "GEOMETRY"
|
||||||
#define MAXIMIZED "MAXIMIZED"
|
#define MAXIMIZED "MAXIMIZED"
|
||||||
|
#define MINIMIZE_TO_TRAY "MINIMIZE_TO_TRAY"
|
||||||
|
#define START_TO_TRAY "START_TO_TRAY"
|
||||||
#define DOUBLE_PAGE "DOUBLE_PAGE"
|
#define DOUBLE_PAGE "DOUBLE_PAGE"
|
||||||
#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE"
|
#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE"
|
||||||
#define BACKGROUND_COLOR "BACKGROUND_COLOR"
|
#define BACKGROUND_COLOR "BACKGROUND_COLOR"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user