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
|
||||
}
|
||||
|
||||
macx {
|
||||
HEADERS += trayhandler.h
|
||||
OBJECTIVE_SOURCES += trayhandler.mm
|
||||
}
|
||||
|
||||
include(./server/server.pri)
|
||||
include(../custom_widgets/custom_widgets_yacreaderlibrary.pri)
|
||||
|
||||
|
@ -86,6 +86,9 @@
|
||||
#ifdef Q_OS_WIN
|
||||
#include <shellapi.h>
|
||||
#endif
|
||||
#ifdef Q_OS_MACOS
|
||||
#include "trayhandler.h"
|
||||
#endif
|
||||
|
||||
LibraryWindow::LibraryWindow()
|
||||
: 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
|
||||
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
|
||||
{
|
||||
QMainWindow::changeEvent(event);
|
||||
// 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);
|
||||
}
|
||||
|
||||
void LibraryWindow::doLayout()
|
||||
{
|
||||
|
@ -385,7 +385,7 @@ public slots:
|
||||
void checkMaxNumLibraries();
|
||||
void showErrorUpgradingLibrary(const QString &path);
|
||||
|
||||
//void changeEvent(QEvent *event);
|
||||
void changeEvent(QEvent *event);
|
||||
|
||||
private:
|
||||
//fullscreen mode in Windows for preventing this bug: QTBUG-41309 https://bugreports.qt.io/browse/QTBUG-41309
|
||||
@ -394,9 +394,6 @@ private:
|
||||
QSize previousSize;
|
||||
std::future<void> upgradeLibraryFuture;
|
||||
QSystemTrayIcon trayIcon;
|
||||
|
||||
private slots:
|
||||
//void trayActivation(QSystemTrayIcon::ActivationReason reason);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -20,6 +20,9 @@
|
||||
#include "yacreader_libraries.h"
|
||||
#include "exit_check.h"
|
||||
#include "opengl_checker.h"
|
||||
#ifdef Q_OS_MACOS
|
||||
#include "trayhandler.h"
|
||||
#endif
|
||||
|
||||
#include "QsLog.h"
|
||||
#include "QsLogDest.h"
|
||||
@ -127,9 +130,12 @@ int main(int argc, char **argv)
|
||||
app.setApplicationVersion(VERSION);
|
||||
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")) {
|
||||
app.setWindowIcon(QIcon::fromTheme("YACReaderLibrary"));
|
||||
}
|
||||
// TODO: We might want to add a fallback icon here.
|
||||
|
||||
QString destLog = YACReader::getSettingsPath() + "/yacreaderlibrary.log";
|
||||
QDir().mkpath(YACReader::getSettingsPath());
|
||||
@ -210,7 +216,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
#ifdef SERVER_RELEASE
|
||||
QSettings *settings = new QSettings(YACReader::getSettingsPath() + "/YACReaderLibrary.ini", QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
QSettings * settings = new QSettings(YACReader::getSettingsPath()+"/YACReaderLibrary.ini",QSettings::IniFormat); //TODO unificar la creaci<63>n del fichero de config con el servidor
|
||||
settings->beginGroup("libraryConfig");
|
||||
|
||||
s = new Startup();
|
||||
@ -235,7 +241,7 @@ int main(int argc, char **argv)
|
||||
|
||||
auto mw = new LibraryWindow();
|
||||
|
||||
mw->connect(localServer, SIGNAL(comicUpdated(quint64, const ComicDB &)), mw, SLOT(updateComicsView(quint64, const ComicDB &)), Qt::QueuedConnection);
|
||||
mw->connect(localServer,SIGNAL(comicUpdated(quint64, const ComicDB &)),mw,SLOT(updateComicsView(quint64, const ComicDB &)), Qt::QueuedConnection);
|
||||
|
||||
//connections to localServer
|
||||
|
||||
|
@ -43,6 +43,9 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
||||
#ifndef NO_OPENGL
|
||||
sw->hide();
|
||||
#endif
|
||||
// Tray icon settings
|
||||
QGroupBox * trayIconBox = new QGroupBox(tr("Tray icon settings"));
|
||||
QVBoxLayout * trayLayout = new QVBoxLayout();
|
||||
|
||||
auto apiKeyLayout = new QVBoxLayout();
|
||||
auto apiKeyButton = new QPushButton(tr("Edit Comic Vine API key"));
|
||||
@ -115,6 +118,7 @@ OptionsDialog::OptionsDialog(QWidget *parent)
|
||||
|
||||
auto generalW = new QWidget;
|
||||
generalW->setLayout(generalLayout);
|
||||
generalLayout->addWidget(trayIconBox);
|
||||
generalLayout->addWidget(shortcutsBox);
|
||||
generalLayout->addWidget(apiKeyBox);
|
||||
generalLayout->addStretch();
|
||||
@ -146,6 +150,10 @@ void OptionsDialog::restoreOptions(QSettings *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();
|
||||
|
||||
useBackgroundImageCheck->setChecked(useBackgroundImage);
|
||||
|
@ -19,23 +19,20 @@ public slots:
|
||||
void editApiKey();
|
||||
void restoreOptions(QSettings *settings) override;
|
||||
|
||||
private slots:
|
||||
private slots:
|
||||
void useBackgroundImageCheckClicked(bool checked);
|
||||
void backgroundImageOpacitySliderChanged(int value);
|
||||
void backgroundImageBlurRadiusSliderChanged(int value);
|
||||
void useCurrentComicCoverCheckClicked(bool checked);
|
||||
void resetToDefaults();
|
||||
|
||||
private:
|
||||
QCheckBox *useBackgroundImageCheck;
|
||||
QCheckBox *useCurrentComicCoverCheck;
|
||||
QSlider *backgroundImageOpacitySlider;
|
||||
QSlider *backgroundImageBlurRadiusSlider;
|
||||
QLabel *opacityLabel;
|
||||
QLabel *blurLabel;
|
||||
QPushButton *resetButton;
|
||||
|
||||
QCheckBox *displayContinueReadingBannerCheck;
|
||||
private:
|
||||
QCheckBox * useBackgroundImageCheck;
|
||||
QCheckBox * useCurrentComicCoverCheck;
|
||||
QSlider * backgroundImageOpacitySlider;
|
||||
QSlider * backgroundImageBlurRadiusSlider;
|
||||
QLabel * opacityLabel;
|
||||
QLabel * blurLabel;
|
||||
QPushButton * resetButton;
|
||||
};
|
||||
|
||||
#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 Y_WINDOW_GEOMETRY "GEOMETRY"
|
||||
#define MAXIMIZED "MAXIMIZED"
|
||||
#define MINIMIZE_TO_TRAY "MINIMIZE_TO_TRAY"
|
||||
#define START_TO_TRAY "START_TO_TRAY"
|
||||
#define DOUBLE_PAGE "DOUBLE_PAGE"
|
||||
#define DOUBLE_MANGA_PAGE "DOUBLE_MANGA_PAGE"
|
||||
#define BACKGROUND_COLOR "BACKGROUND_COLOR"
|
||||
|
Loading…
x
Reference in New Issue
Block a user