1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Correct for Maximized window

This commit is contained in:
PKEv 2015-03-19 22:24:06 +03:00
parent e3946b4435
commit e940459596
2 changed files with 32 additions and 2 deletions

View File

@ -84,6 +84,7 @@ Widget::Widget(QWidget *parent)
eventFlag(false), eventFlag(false),
eventIcon(false) eventIcon(false)
{ {
installEventFilter(this);
translator = new QTranslator; translator = new QTranslator;
setTranslation(); setTranslation();
} }
@ -223,6 +224,23 @@ void Widget::setTranslation()
QCoreApplication::installTranslator(translator); QCoreApplication::installTranslator(translator);
} }
bool Widget::eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::WindowStateChange && obj != NULL)
{
QWindowStateChangeEvent * ce = static_cast<QWindowStateChangeEvent*>(event);
if (windowState() & Qt::WindowMinimized)
{
if (ce->oldState() & Qt::WindowMaximized)
wasMaximized = true;
else
wasMaximized = false;
}
}
event->accept();
return false;
}
void Widget::updateIcons() void Widget::updateIcons()
{ {
QString status; QString status;
@ -459,16 +477,23 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
{ {
show(); show();
activateWindow(); activateWindow();
showNormal(); if (wasMaximized)
showMaximized();
else
showNormal();
} }
else if (isMinimized()) else if (isMinimized())
{ {
forceShow(); forceShow();
activateWindow(); activateWindow();
showNormal(); if (wasMaximized)
showMaximized();
else
showNormal();
} }
else else
{ {
wasMaximized = isMaximized();
if (Settings::getInstance().getMinimizeToTray()) if (Settings::getInstance().getMinimizeToTray())
hide(); hide();
else else
@ -479,6 +504,7 @@ void Widget::onIconClick(QSystemTrayIcon::ActivationReason reason)
break; break;
} }
case QSystemTrayIcon::MiddleClick: case QSystemTrayIcon::MiddleClick:
wasMaximized = isMaximized();
if (Settings::getInstance().getMinimizeToTray()) if (Settings::getInstance().getMinimizeToTray())
hide(); hide();
else else

View File

@ -51,6 +51,9 @@ class Widget : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
protected:
bool eventFilter(QObject *obj, QEvent *event);
public: public:
explicit Widget(QWidget *parent = 0); explicit Widget(QWidget *parent = 0);
void init(); void init();
@ -176,6 +179,7 @@ private:
QRegExp nameMention, sanitizedNameMention; QRegExp nameMention, sanitizedNameMention;
bool eventFlag; bool eventFlag;
bool eventIcon; bool eventIcon;
bool wasMaximized = false;
}; };
bool toxActivateEventHandler(const QByteArray& data); bool toxActivateEventHandler(const QByteArray& data);