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 "FileDialog.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QPainter>
|
||||
|
||||
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
|
||||
SkinDisplay::enterEvent (QEvent *event)
|
||||
{
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
|
||||
#include <QWidget>
|
||||
class QEvent;
|
||||
class QMouseEvent;
|
||||
class QPaintEvent;
|
||||
|
||||
class Skin;
|
||||
|
@ -35,8 +34,6 @@ class SkinDisplay : public QWidget
|
|||
void fileOpen (void);
|
||||
|
||||
protected:
|
||||
void mousePressEvent (QMouseEvent *);
|
||||
void mouseMoveEvent (QMouseEvent *);
|
||||
void paintEvent (QPaintEvent *event);
|
||||
void enterEvent (QEvent *event);
|
||||
void leaveEvent (QEvent *event);
|
||||
|
@ -44,8 +41,6 @@ class SkinDisplay : public QWidget
|
|||
QWidget *m_mw;
|
||||
QWidget *m_tbar;
|
||||
|
||||
int m_diffX;
|
||||
int m_diffY;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
#include <QMap>
|
||||
class QDir;
|
||||
|
||||
class Skin : public QWidget
|
||||
//class Skin : public QWidget
|
||||
class Skin : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
|
|
@ -19,13 +19,12 @@
|
|||
|
||||
#include "QWidget"
|
||||
#include <QSettings>
|
||||
#include <QMouseEvent>
|
||||
#include <QMoveEvent>
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "equalizerwidget.h"
|
||||
|
||||
EqualizerWindow::EqualizerWindow (QWidget *parent) : QMainWindow (parent)
|
||||
EqualizerWindow::EqualizerWindow (QWidget *parent) : BaseWindow (parent)
|
||||
{
|
||||
m_mw = dynamic_cast<MainWindow *>(parent);
|
||||
|
||||
|
@ -64,21 +63,6 @@ EqualizerWindow::setEnabled (void)
|
|||
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
|
||||
EqualizerWindow::moveEvent (QMoveEvent *event)
|
||||
{
|
||||
|
|
|
@ -16,10 +16,9 @@
|
|||
#ifndef __EQUALIZERWINDOW_H__
|
||||
#define __EQUALIZERWINDOW_H__
|
||||
|
||||
#include <QMainWindow>
|
||||
#include "basewindow.h"
|
||||
|
||||
class QWidget;
|
||||
class QMouseEvent;
|
||||
class QMoveEvent;
|
||||
class QHideEvent;
|
||||
class QShowEvent;
|
||||
|
@ -27,7 +26,7 @@ class QShowEvent;
|
|||
class MainWindow;
|
||||
class EqualizerWidget;
|
||||
|
||||
class EqualizerWindow : public QMainWindow
|
||||
class EqualizerWindow : public BaseWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -43,16 +42,12 @@ class EqualizerWindow : public QMainWindow
|
|||
protected:
|
||||
void hideEvent (QHideEvent *event);
|
||||
void showEvent (QShowEvent *event);
|
||||
void mouseMoveEvent(QMouseEvent *);
|
||||
void mousePressEvent(QMouseEvent *);
|
||||
void moveEvent(QMoveEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
MainWindow *m_mw;
|
||||
EqualizerWidget *m_equalizer;
|
||||
int m_diffx;
|
||||
int m_diffy;
|
||||
};
|
||||
|
||||
#endif // __EQUALIZERWINDOW_H__
|
||||
|
|
|
@ -119,21 +119,6 @@ MainDisplay::setVolume (int 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
|
||||
MainDisplay::setPixmaps (Skin *skin)
|
||||
|
|
|
@ -66,8 +66,6 @@ class MainDisplay : public SkinDisplay
|
|||
PlayStatus *m_playstatus;
|
||||
MainWindow *getMW(void) { return m_mw; }
|
||||
|
||||
void mouseMoveEvent (QMouseEvent *);
|
||||
|
||||
public slots:
|
||||
void setPixmaps(Skin *skin);
|
||||
void setStatus (Xmms::Playback::Status status);
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <QPluginLoader>
|
||||
#include <qplugin.h>
|
||||
|
||||
MainWindow::MainWindow (QWidget *parent) : QMainWindow (parent)
|
||||
MainWindow::MainWindow (QWidget *parent) : BaseWindow (parent)
|
||||
{
|
||||
QSettings s;
|
||||
|
||||
|
@ -130,5 +130,15 @@ MainWindow::moveEvent (QMoveEvent *event)
|
|||
{
|
||||
QSettings s;
|
||||
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__
|
||||
#define __MAINWINDOW_H__
|
||||
|
||||
#include <QMainWindow>
|
||||
#include <QSettings>
|
||||
#include "basewindow.h"
|
||||
|
||||
#include <QSettings>
|
||||
class QWidget;
|
||||
|
||||
class MainDisplay;
|
||||
|
@ -26,7 +26,7 @@ class ShadedDisplay;
|
|||
class PlaylistWindow;
|
||||
class EqualizerWindow;
|
||||
|
||||
class MainWindow : public QMainWindow
|
||||
class MainWindow : public BaseWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
@ -55,6 +55,8 @@ class MainWindow : public QMainWindow
|
|||
ShadedDisplay *m_shaded;
|
||||
EqualizerWindow *m_equalizer;
|
||||
PlaylistWindow *m_playlistwin;
|
||||
|
||||
QMap<QWidget *,QPoint> m_connectedWidgets;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
#include "playlistwindow.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
#include <QMoveEvent>
|
||||
#include <QResizeEvent>
|
||||
#include <QPoint>
|
||||
|
||||
#include "Button.h"
|
||||
#include "playlistwidget.h"
|
||||
|
@ -28,7 +28,7 @@
|
|||
|
||||
#include "mainwindow.h"
|
||||
|
||||
PlaylistWindow::PlaylistWindow (QWidget *parent) : QMainWindow (parent)
|
||||
PlaylistWindow::PlaylistWindow (QWidget *parent) : BaseWindow (parent)
|
||||
{
|
||||
QSettings s;
|
||||
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
|
||||
PlaylistWindow::moveEvent (QMoveEvent *event)
|
||||
{
|
||||
|
|
|
@ -18,14 +18,14 @@
|
|||
#define __PLAYLISTWINDOW_H__
|
||||
|
||||
// Qt classes
|
||||
#include <QMainWindow>
|
||||
#include "basewindow.h"
|
||||
|
||||
class QEvent;
|
||||
class QMouseEvent;
|
||||
class QMoveEvent;
|
||||
class QResizeEvent;
|
||||
class QHideEvent;
|
||||
class QShowEvent;
|
||||
class QPoint;
|
||||
|
||||
// our own classes
|
||||
class Button;
|
||||
|
@ -33,7 +33,7 @@ class MainWindow;
|
|||
class PlaylistWidget;
|
||||
class PlaylistShade;
|
||||
|
||||
class PlaylistWindow : public QMainWindow {
|
||||
class PlaylistWindow : public BaseWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
@ -51,21 +51,15 @@ class PlaylistWindow : public QMainWindow {
|
|||
protected:
|
||||
void hideEvent (QHideEvent *event);
|
||||
void showEvent (QShowEvent *event);
|
||||
void mousePressEvent (QMouseEvent *event);
|
||||
void mouseMoveEvent (QMouseEvent *event);
|
||||
void enterEvent (QEvent *event);
|
||||
void leaveEvent (QEvent *event);
|
||||
void moveEvent (QMoveEvent *event);
|
||||
void resizeEvent (QResizeEvent *event);
|
||||
|
||||
|
||||
private:
|
||||
PlaylistWidget *m_playlist;
|
||||
PlaylistShade *m_shaded;
|
||||
|
||||
int m_diffx;
|
||||
int m_diffy;
|
||||
|
||||
Button *m_shadebtn;
|
||||
Button *m_closebtn;
|
||||
MainWindow *m_mw;
|
||||
|
|
|
@ -18,6 +18,7 @@ HEADERS += PixWidget.h \
|
|||
PlayStatus.h \
|
||||
SkinChooser.h \
|
||||
settingsdialog.h \
|
||||
basewindow.h \
|
||||
VolumeSlider.h \
|
||||
FileDialog.h \
|
||||
BrowseModel.h \
|
||||
|
@ -38,6 +39,7 @@ SOURCES += main.cpp \
|
|||
PlayStatus.cpp \
|
||||
SkinChooser.cpp \
|
||||
settingsdialog.cpp \
|
||||
basewindow.cpp \
|
||||
VolumeSlider.cpp \
|
||||
FileDialog.cpp \
|
||||
BrowseModel.cpp \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue