Make windows snap to each other
This commit is contained in:
parent
ab988d8496
commit
94ca829e98
12 changed files with 29 additions and 94 deletions
|
@ -23,7 +23,6 @@
|
||||||
#include "TitleBar.h"
|
#include "TitleBar.h"
|
||||||
#include "FileDialog.h"
|
#include "FileDialog.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
|
|
||||||
SkinDisplay::SkinDisplay (QWidget *parent) : QWidget(parent)
|
SkinDisplay::SkinDisplay (QWidget *parent) : QWidget(parent)
|
||||||
|
@ -41,21 +40,6 @@ SkinDisplay::setPixmaps (Skin *skin)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
SkinDisplay::mousePressEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
dynamic_cast<MainWindow *>(getMW())->raisePL ();
|
|
||||||
m_diffX = event->x();
|
|
||||||
m_diffY = event->y();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
SkinDisplay::mouseMoveEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
m_mw->move (event->globalPos().x() - m_diffX,
|
|
||||||
event->globalPos().y() - m_diffY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SkinDisplay::enterEvent (QEvent *event)
|
SkinDisplay::enterEvent (QEvent *event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
class QEvent;
|
class QEvent;
|
||||||
class QMouseEvent;
|
|
||||||
class QPaintEvent;
|
class QPaintEvent;
|
||||||
|
|
||||||
class Skin;
|
class Skin;
|
||||||
|
@ -35,8 +34,6 @@ class SkinDisplay : public QWidget
|
||||||
void fileOpen (void);
|
void fileOpen (void);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void mousePressEvent (QMouseEvent *);
|
|
||||||
void mouseMoveEvent (QMouseEvent *);
|
|
||||||
void paintEvent (QPaintEvent *event);
|
void paintEvent (QPaintEvent *event);
|
||||||
void enterEvent (QEvent *event);
|
void enterEvent (QEvent *event);
|
||||||
void leaveEvent (QEvent *event);
|
void leaveEvent (QEvent *event);
|
||||||
|
@ -44,8 +41,6 @@ class SkinDisplay : public QWidget
|
||||||
QWidget *m_mw;
|
QWidget *m_mw;
|
||||||
QWidget *m_tbar;
|
QWidget *m_tbar;
|
||||||
|
|
||||||
int m_diffX;
|
|
||||||
int m_diffY;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -23,7 +23,8 @@
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
class QDir;
|
class QDir;
|
||||||
|
|
||||||
class Skin : public QWidget
|
//class Skin : public QWidget
|
||||||
|
class Skin : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -19,13 +19,12 @@
|
||||||
|
|
||||||
#include "QWidget"
|
#include "QWidget"
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QMoveEvent>
|
#include <QMoveEvent>
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "equalizerwidget.h"
|
#include "equalizerwidget.h"
|
||||||
|
|
||||||
EqualizerWindow::EqualizerWindow (QWidget *parent) : QMainWindow (parent)
|
EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent)
|
||||||
{
|
{
|
||||||
m_mw = dynamic_cast<MainWindow *>(parent);
|
m_mw = dynamic_cast<MainWindow *>(parent);
|
||||||
|
|
||||||
|
@ -64,21 +63,6 @@ EqualizerWindow::setEnabled (void)
|
||||||
qDebug ("test");
|
qDebug ("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
EqualizerWindow::mousePressEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
m_diffx = event->pos().x();
|
|
||||||
m_diffy = event->pos().y();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
EqualizerWindow::mouseMoveEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
move(event->globalPos().x() - m_diffx,
|
|
||||||
event->globalPos().y() - m_diffy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
EqualizerWindow::moveEvent (QMoveEvent *event)
|
EqualizerWindow::moveEvent (QMoveEvent *event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,10 +16,9 @@
|
||||||
#ifndef __EQUALIZERWINDOW_H__
|
#ifndef __EQUALIZERWINDOW_H__
|
||||||
#define __EQUALIZERWINDOW_H__
|
#define __EQUALIZERWINDOW_H__
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include "basewindow.h"
|
||||||
|
|
||||||
class QWidget;
|
class QWidget;
|
||||||
class QMouseEvent;
|
|
||||||
class QMoveEvent;
|
class QMoveEvent;
|
||||||
class QHideEvent;
|
class QHideEvent;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
|
@ -27,7 +26,7 @@ class QShowEvent;
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
class EqualizerWidget;
|
class EqualizerWidget;
|
||||||
|
|
||||||
class EqualizerWindow : public QMainWindow
|
class EqualizerWindow : public BaseWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -43,16 +42,12 @@ class EqualizerWindow : public QMainWindow
|
||||||
protected:
|
protected:
|
||||||
void hideEvent (QHideEvent *event);
|
void hideEvent (QHideEvent *event);
|
||||||
void showEvent (QShowEvent *event);
|
void showEvent (QShowEvent *event);
|
||||||
void mouseMoveEvent(QMouseEvent *);
|
|
||||||
void mousePressEvent(QMouseEvent *);
|
|
||||||
void moveEvent(QMoveEvent *event);
|
void moveEvent(QMoveEvent *event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MainWindow *m_mw;
|
MainWindow *m_mw;
|
||||||
EqualizerWidget *m_equalizer;
|
EqualizerWidget *m_equalizer;
|
||||||
int m_diffx;
|
|
||||||
int m_diffy;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __EQUALIZERWINDOW_H__
|
#endif // __EQUALIZERWINDOW_H__
|
||||||
|
|
|
@ -119,21 +119,6 @@ MainDisplay::setVolume (int volume)
|
||||||
xmmsh.volumeSet((uint)volume);
|
xmmsh.volumeSet((uint)volume);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
MainDisplay::mouseMoveEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
MainWindow *mw = dynamic_cast<MainWindow *>(window ());
|
|
||||||
PlaylistWindow *pl = mw->getPL ();
|
|
||||||
|
|
||||||
m_mw->move (event->globalPos().x() - m_diffX,
|
|
||||||
event->globalPos().y() - m_diffY);
|
|
||||||
|
|
||||||
if (!pl || !pl->isVisible ())
|
|
||||||
return;
|
|
||||||
|
|
||||||
pl->move (event->globalPos().x() - m_diffX,
|
|
||||||
event->globalPos().y() - m_diffY + size().height());
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainDisplay::setPixmaps (Skin *skin)
|
MainDisplay::setPixmaps (Skin *skin)
|
||||||
|
|
|
@ -66,8 +66,6 @@ class MainDisplay : public SkinDisplay
|
||||||
PlayStatus *m_playstatus;
|
PlayStatus *m_playstatus;
|
||||||
MainWindow *getMW(void) { return m_mw; }
|
MainWindow *getMW(void) { return m_mw; }
|
||||||
|
|
||||||
void mouseMoveEvent (QMouseEvent *);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setPixmaps(Skin *skin);
|
void setPixmaps(Skin *skin);
|
||||||
void setStatus (Xmms::Playback::Status status);
|
void setStatus (Xmms::Playback::Status status);
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
#include <qplugin.h>
|
#include <qplugin.h>
|
||||||
|
|
||||||
MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent)
|
MainWindow::MainWindow (QWidget *parent) : BaseWindow (parent)
|
||||||
{
|
{
|
||||||
QSettings s;
|
QSettings s;
|
||||||
|
|
||||||
|
@ -130,5 +130,15 @@ MainWindow::moveEvent (QMoveEvent *event)
|
||||||
{
|
{
|
||||||
QSettings s;
|
QSettings s;
|
||||||
s.setValue ("mainwindow/pos", pos ());
|
s.setValue ("mainwindow/pos", pos ());
|
||||||
}
|
|
||||||
|
|
||||||
|
// move all connected windows to their new position
|
||||||
|
// at the moment connected windows can be m_playlistwin and m_equalizer
|
||||||
|
if (!m_connectedWidgets.isEmpty ()) {
|
||||||
|
QMap<QWidget *,QPoint>::const_iterator i
|
||||||
|
= m_connectedWidgets.constBegin ();
|
||||||
|
while (i != m_connectedWidgets.constEnd ()) {
|
||||||
|
i.key()->move (pos () + i.value ());
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -16,9 +16,9 @@
|
||||||
#ifndef __MAINWINDOW_H__
|
#ifndef __MAINWINDOW_H__
|
||||||
#define __MAINWINDOW_H__
|
#define __MAINWINDOW_H__
|
||||||
|
|
||||||
#include <QMainWindow>
|
#include "basewindow.h"
|
||||||
#include <QSettings>
|
|
||||||
|
|
||||||
|
#include <QSettings>
|
||||||
class QWidget;
|
class QWidget;
|
||||||
|
|
||||||
class MainDisplay;
|
class MainDisplay;
|
||||||
|
@ -26,7 +26,7 @@ class ShadedDisplay;
|
||||||
class PlaylistWindow;
|
class PlaylistWindow;
|
||||||
class EqualizerWindow;
|
class EqualizerWindow;
|
||||||
|
|
||||||
class MainWindow : public QMainWindow
|
class MainWindow : public BaseWindow
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -55,6 +55,8 @@ class MainWindow : public QMainWindow
|
||||||
ShadedDisplay *m_shaded;
|
ShadedDisplay *m_shaded;
|
||||||
EqualizerWindow *m_equalizer;
|
EqualizerWindow *m_equalizer;
|
||||||
PlaylistWindow *m_playlistwin;
|
PlaylistWindow *m_playlistwin;
|
||||||
|
|
||||||
|
QMap<QWidget *,QPoint> m_connectedWidgets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,9 @@
|
||||||
|
|
||||||
#include "playlistwindow.h"
|
#include "playlistwindow.h"
|
||||||
|
|
||||||
#include <QMouseEvent>
|
|
||||||
#include <QMoveEvent>
|
#include <QMoveEvent>
|
||||||
#include <QResizeEvent>
|
#include <QResizeEvent>
|
||||||
|
#include <QPoint>
|
||||||
|
|
||||||
#include "Button.h"
|
#include "Button.h"
|
||||||
#include "playlistwidget.h"
|
#include "playlistwidget.h"
|
||||||
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
|
||||||
PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent)
|
PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent)
|
||||||
{
|
{
|
||||||
QSettings s;
|
QSettings s;
|
||||||
m_mw = dynamic_cast<MainWindow *>(parent);
|
m_mw = dynamic_cast<MainWindow *>(parent);
|
||||||
|
@ -132,21 +132,6 @@ PlaylistWindow::resizeEvent (QResizeEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
PlaylistWindow::mousePressEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
m_diffx = event->pos ().x ();
|
|
||||||
m_diffy = event->pos ().y ();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
PlaylistWindow::mouseMoveEvent (QMouseEvent *event)
|
|
||||||
{
|
|
||||||
move (event->globalPos().x() - m_diffx,
|
|
||||||
event->globalPos().y() - m_diffy);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PlaylistWindow::moveEvent (QMoveEvent *event)
|
PlaylistWindow::moveEvent (QMoveEvent *event)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,14 +18,14 @@
|
||||||
#define __PLAYLISTWINDOW_H__
|
#define __PLAYLISTWINDOW_H__
|
||||||
|
|
||||||
// Qt classes
|
// Qt classes
|
||||||
#include <QMainWindow>
|
#include "basewindow.h"
|
||||||
|
|
||||||
class QEvent;
|
class QEvent;
|
||||||
class QMouseEvent;
|
|
||||||
class QMoveEvent;
|
class QMoveEvent;
|
||||||
class QResizeEvent;
|
class QResizeEvent;
|
||||||
class QHideEvent;
|
class QHideEvent;
|
||||||
class QShowEvent;
|
class QShowEvent;
|
||||||
|
class QPoint;
|
||||||
|
|
||||||
// our own classes
|
// our own classes
|
||||||
class Button;
|
class Button;
|
||||||
|
@ -33,7 +33,7 @@ class MainWindow;
|
||||||
class PlaylistWidget;
|
class PlaylistWidget;
|
||||||
class PlaylistShade;
|
class PlaylistShade;
|
||||||
|
|
||||||
class PlaylistWindow : public QMainWindow {
|
class PlaylistWindow : public BaseWindow {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -51,21 +51,15 @@ class PlaylistWindow : public QMainWindow {
|
||||||
protected:
|
protected:
|
||||||
void hideEvent (QHideEvent *event);
|
void hideEvent (QHideEvent *event);
|
||||||
void showEvent (QShowEvent *event);
|
void showEvent (QShowEvent *event);
|
||||||
void mousePressEvent (QMouseEvent *event);
|
|
||||||
void mouseMoveEvent (QMouseEvent *event);
|
|
||||||
void enterEvent (QEvent *event);
|
void enterEvent (QEvent *event);
|
||||||
void leaveEvent (QEvent *event);
|
void leaveEvent (QEvent *event);
|
||||||
void moveEvent (QMoveEvent *event);
|
void moveEvent (QMoveEvent *event);
|
||||||
void resizeEvent (QResizeEvent *event);
|
void resizeEvent (QResizeEvent *event);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PlaylistWidget *m_playlist;
|
PlaylistWidget *m_playlist;
|
||||||
PlaylistShade *m_shaded;
|
PlaylistShade *m_shaded;
|
||||||
|
|
||||||
int m_diffx;
|
|
||||||
int m_diffy;
|
|
||||||
|
|
||||||
Button *m_shadebtn;
|
Button *m_shadebtn;
|
||||||
Button *m_closebtn;
|
Button *m_closebtn;
|
||||||
MainWindow *m_mw;
|
MainWindow *m_mw;
|
||||||
|
|
|
@ -18,6 +18,7 @@ HEADERS += PixWidget.h \
|
||||||
PlayStatus.h \
|
PlayStatus.h \
|
||||||
SkinChooser.h \
|
SkinChooser.h \
|
||||||
settingsdialog.h \
|
settingsdialog.h \
|
||||||
|
basewindow.h \
|
||||||
VolumeSlider.h \
|
VolumeSlider.h \
|
||||||
FileDialog.h \
|
FileDialog.h \
|
||||||
BrowseModel.h \
|
BrowseModel.h \
|
||||||
|
@ -38,6 +39,7 @@ SOURCES += main.cpp \
|
||||||
PlayStatus.cpp \
|
PlayStatus.cpp \
|
||||||
SkinChooser.cpp \
|
SkinChooser.cpp \
|
||||||
settingsdialog.cpp \
|
settingsdialog.cpp \
|
||||||
|
basewindow.cpp \
|
||||||
VolumeSlider.cpp \
|
VolumeSlider.cpp \
|
||||||
FileDialog.cpp \
|
FileDialog.cpp \
|
||||||
BrowseModel.cpp \
|
BrowseModel.cpp \
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue