OTHER: Fix memleak and fixed small bug in hideEvent handlers
When promoe was minimized or on a different virtual desktop when it was quit, the visible setting of playlist and equalizer was set to false. So even when those two were visible before switching to a different desktop they where set to closed when promoe was started the next time
This commit is contained in:
parent
4df3266088
commit
c7e1a7fa6b
8 changed files with 105 additions and 112 deletions
|
@ -19,49 +19,66 @@
|
|||
|
||||
#include <QApplication>
|
||||
#include <QWidgetList>
|
||||
#include <QMouseEvent>
|
||||
#include <QPoint>
|
||||
#include <QSettings>
|
||||
|
||||
#include <QHideEvent>
|
||||
#include <QShowEvent>
|
||||
#include <QMoveEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#include <QtDebug>
|
||||
|
||||
BaseWindow::BaseWindow (QWidget *parent) : QMainWindow (parent)
|
||||
{
|
||||
}
|
||||
|
||||
bool
|
||||
BaseWindow::touches (QWidget *widget)
|
||||
|
||||
// Qt Event Handlers
|
||||
void
|
||||
BaseWindow::hideEvent (QHideEvent *event)
|
||||
{
|
||||
if (this == widget) {
|
||||
return true;
|
||||
if (event->spontaneous ()) {
|
||||
event->ignore ();
|
||||
return;
|
||||
}
|
||||
|
||||
qint32 left = x ();
|
||||
qint32 right = left + width ();
|
||||
qint32 top = y ();
|
||||
qint32 bottom = top + height ();
|
||||
|
||||
qint32 w_left = widget->x ();
|
||||
qint32 w_right = w_left + widget->width ();
|
||||
qint32 w_top = widget->y ();
|
||||
qint32 w_bottom = w_top + widget->height ();
|
||||
|
||||
if (( (top <= w_bottom) && (bottom >= w_top) &&
|
||||
((left == w_right || right == w_left)) ) ||
|
||||
( (left <= w_right) && (right >= w_left) &&
|
||||
((top == w_bottom) || (bottom == w_top) ) )) {
|
||||
return true;
|
||||
if ((objectName ().isEmpty ()) | (objectName () == "MainWindow")) {
|
||||
event->ignore ();
|
||||
return;
|
||||
}
|
||||
|
||||
return false;
|
||||
QSettings s;
|
||||
s.setValue (objectName ()+"/visible", false);
|
||||
|
||||
emit visibilityChanged (false);
|
||||
}
|
||||
|
||||
MainWindow *
|
||||
BaseWindow::mw ()
|
||||
void
|
||||
BaseWindow::showEvent (QShowEvent *event)
|
||||
{
|
||||
//MainWindow is the only BaseWindow without a *parent
|
||||
if (parent ()) {
|
||||
return qobject_cast<MainWindow *>(parent ());
|
||||
} else {
|
||||
return qobject_cast<MainWindow *>(this);
|
||||
if (objectName ().isEmpty ()) {
|
||||
event->ignore ();
|
||||
return;
|
||||
}
|
||||
|
||||
QSettings s;
|
||||
s.setValue (objectName ()+"/visible", true);
|
||||
mw ()->attachWidgets ();
|
||||
|
||||
emit visibilityChanged (true);
|
||||
}
|
||||
|
||||
void
|
||||
BaseWindow::moveEvent (QMoveEvent *event)
|
||||
{
|
||||
if (objectName ().isEmpty ()) {
|
||||
event->ignore ();
|
||||
return;
|
||||
}
|
||||
|
||||
QSettings s;
|
||||
s.setValue (objectName ()+"/pos", pos ());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -91,6 +108,45 @@ BaseWindow::mouseMoveEvent (QMouseEvent *event)
|
|||
|
||||
}
|
||||
|
||||
// Helper classes vor snapping windows
|
||||
MainWindow *
|
||||
BaseWindow::mw ()
|
||||
{
|
||||
//MainWindow is the only BaseWindow without a *parent
|
||||
if (parent ()) {
|
||||
return qobject_cast<MainWindow *>(parent ());
|
||||
} else {
|
||||
return qobject_cast<MainWindow *>(this);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
BaseWindow::touches (QWidget *widget)
|
||||
{
|
||||
if (this == widget) {
|
||||
return true;
|
||||
}
|
||||
|
||||
qint32 left = x ();
|
||||
qint32 right = left + width ();
|
||||
qint32 top = y ();
|
||||
qint32 bottom = top + height ();
|
||||
|
||||
qint32 w_left = widget->x ();
|
||||
qint32 w_right = w_left + widget->width ();
|
||||
qint32 w_top = widget->y ();
|
||||
qint32 w_bottom = w_top + widget->height ();
|
||||
|
||||
if (( (top <= w_bottom) && (bottom >= w_top) &&
|
||||
((left == w_right || right == w_left)) ) ||
|
||||
( (left <= w_right) && (right >= w_left) &&
|
||||
((top == w_bottom) || (bottom == w_top) ) )) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
QPoint
|
||||
BaseWindow::snapWindow(QPoint pos, AttachedWindowMap attached)
|
||||
{
|
||||
|
|
|
@ -20,24 +20,33 @@
|
|||
#include <QMainWindow>
|
||||
#include <QPoint>
|
||||
#include <QMap>
|
||||
class QMouseEvent;
|
||||
class QPoint;
|
||||
|
||||
class MainWindow;
|
||||
class QHideEvent;
|
||||
class QShowEvent;
|
||||
class QMoveEvent;
|
||||
class QMouseEvent;
|
||||
|
||||
class MainWindow;
|
||||
class BaseWindow;
|
||||
typedef QMap<BaseWindow *, QPoint> AttachedWindowMap;
|
||||
|
||||
class BaseWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void visibilityChanged (bool visible);
|
||||
|
||||
public:
|
||||
BaseWindow (QWidget *parent);
|
||||
|
||||
|
||||
bool touches (QWidget *);
|
||||
MainWindow * mw ();
|
||||
|
||||
protected:
|
||||
void hideEvent (QHideEvent *event);
|
||||
void showEvent (QShowEvent *event);
|
||||
void moveEvent (QMoveEvent *event);
|
||||
void mousePressEvent (QMouseEvent *event);
|
||||
void mouseReleaseEvent (QMouseEvent *event);
|
||||
void mouseMoveEvent (QMouseEvent *event);
|
||||
|
|
|
@ -17,13 +17,13 @@
|
|||
|
||||
#include "QWidget"
|
||||
#include <QSettings>
|
||||
#include <QMoveEvent>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "equalizerwidget.h"
|
||||
|
||||
EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent)
|
||||
{
|
||||
setObjectName ("equalizer");
|
||||
m_mw = dynamic_cast<MainWindow *>(parent);
|
||||
|
||||
setWindowFlags (Qt::Dialog | Qt::FramelessWindowHint);
|
||||
|
@ -37,34 +37,8 @@ EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent)
|
|||
setFixedSize (275, 116);
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWindow::hideEvent (QHideEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("equalizer/visible", false);
|
||||
|
||||
emit visibilityChanged (false);
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWindow::showEvent (QShowEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("equalizer/visible", true);
|
||||
m_mw->attachWidgets ();
|
||||
|
||||
emit visibilityChanged (true);
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWindow::setEnabled (void)
|
||||
{
|
||||
qDebug ("test");
|
||||
}
|
||||
|
||||
void
|
||||
EqualizerWindow::moveEvent (QMoveEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("equalizer/pos", pos ());
|
||||
}
|
||||
|
|
|
@ -19,10 +19,6 @@
|
|||
#include "basewindow.h"
|
||||
|
||||
class QWidget;
|
||||
class QMoveEvent;
|
||||
class QHideEvent;
|
||||
class QShowEvent;
|
||||
|
||||
class MainWindow;
|
||||
class EqualizerWidget;
|
||||
|
||||
|
@ -33,18 +29,9 @@ class EqualizerWindow : public BaseWindow
|
|||
EqualizerWindow(QWidget *parent);
|
||||
~EqualizerWindow() {}
|
||||
|
||||
signals:
|
||||
void visibilityChanged(bool visible);
|
||||
|
||||
public slots:
|
||||
void setEnabled (void);
|
||||
|
||||
protected:
|
||||
void hideEvent (QHideEvent *event);
|
||||
void showEvent (QShowEvent *event);
|
||||
void moveEvent(QMoveEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
MainWindow *m_mw;
|
||||
EqualizerWidget *m_equalizer;
|
||||
|
|
|
@ -39,6 +39,7 @@ MainWindow::MainWindow (QWidget *parent) : BaseWindow (parent)
|
|||
{
|
||||
QSettings s;
|
||||
|
||||
setWindowTitle (App->applicationName ());
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
setMaximumSize (275, 116);
|
||||
#ifndef _WIN32
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "playlistwindow.h"
|
||||
|
||||
#include <QMoveEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QPoint>
|
||||
#include <QIcon>
|
||||
|
@ -27,15 +26,16 @@
|
|||
|
||||
PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent)
|
||||
{
|
||||
QSettings s;
|
||||
setObjectName ("playlist"); // Name of the config group
|
||||
#ifndef _WIN32
|
||||
setWindowIcon (QIcon (":icon.png"));
|
||||
#endif
|
||||
|
||||
QSettings s;
|
||||
setWindowFlags (Qt::Dialog | Qt::FramelessWindowHint);
|
||||
setAttribute (Qt::WA_DeleteOnClose);
|
||||
|
||||
s.beginGroup ("playlist");
|
||||
s.beginGroup (objectName ());
|
||||
if (!s.contains ("size")) {
|
||||
s.setValue ("size", QSize (275, 350));
|
||||
}
|
||||
|
@ -58,26 +58,6 @@ PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent)
|
|||
//setSizeIncrement (25, 29);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWindow::hideEvent (QHideEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("playlist/visible", false);
|
||||
|
||||
emit visibilityChanged (false);
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWindow::showEvent (QShowEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("playlist/visible", true);
|
||||
mw ()->attachWidgets ();
|
||||
|
||||
emit visibilityChanged (true);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PlaylistWindow::switchDisplay (void)
|
||||
{
|
||||
|
@ -119,13 +99,6 @@ PlaylistWindow::resizeEvent (QResizeEvent *event)
|
|||
mw ()->attachWidgets ();
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWindow::moveEvent (QMoveEvent *event)
|
||||
{
|
||||
QSettings s;
|
||||
s.setValue ("playlist/pos", pos ());
|
||||
}
|
||||
|
||||
void
|
||||
PlaylistWindow::enterEvent (QEvent *event)
|
||||
{
|
||||
|
|
|
@ -20,10 +20,7 @@
|
|||
#include "basewindow.h"
|
||||
|
||||
class QEvent;
|
||||
class QMoveEvent;
|
||||
class QResizeEvent;
|
||||
class QHideEvent;
|
||||
class QShowEvent;
|
||||
class QPoint;
|
||||
|
||||
// our own classes
|
||||
|
@ -41,8 +38,6 @@ class PlaylistWindow : public BaseWindow {
|
|||
void setActive (bool);
|
||||
|
||||
signals:
|
||||
void visibilityChanged(bool visible);
|
||||
|
||||
// setTime is used to set playtime in playlistcontrols
|
||||
void setDisplayTime (int seconds);
|
||||
|
||||
|
@ -50,11 +45,8 @@ class PlaylistWindow : public BaseWindow {
|
|||
void switchDisplay (void);
|
||||
|
||||
protected:
|
||||
void hideEvent (QHideEvent *event);
|
||||
void showEvent (QShowEvent *event);
|
||||
void enterEvent (QEvent *event);
|
||||
void leaveEvent (QEvent *event);
|
||||
void moveEvent (QMoveEvent *event);
|
||||
void resizeEvent (QResizeEvent *event);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue