mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Frameless dialog position/size fixes
Fixed frameless dialog size and position on main window resize and move
This commit is contained in:
parent
b45f61ec54
commit
ba5a092ad7
3 changed files with 90 additions and 19 deletions
|
@ -717,9 +717,9 @@ void Menu::loginForCurrentDomain() {
|
|||
|
||||
void Menu::editPreferences() {
|
||||
if (!_preferencesDialog) {
|
||||
Application::getInstance()->getWindow()->addDockWidget(Qt::LeftDockWidgetArea, _preferencesDialog = new PreferencesDialog());
|
||||
_preferencesDialog = new PreferencesDialog(Application::getInstance()->getWindow());
|
||||
_preferencesDialog->show();
|
||||
} else {
|
||||
Application::getInstance()->getWindow()->removeDockWidget(_preferencesDialog);
|
||||
_preferencesDialog->close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,26 +6,65 @@
|
|||
//
|
||||
//
|
||||
|
||||
#include <QDesktopWidget>
|
||||
#include <QFile>
|
||||
#include <QPushButton>
|
||||
#include <QSizeGrip>
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "Application.h"
|
||||
#include "FramelessDialog.h"
|
||||
|
||||
const int RESIZE_HANDLE_WIDTH = 7;
|
||||
|
||||
FramelessDialog::FramelessDialog(QWidget *parent, Qt::WindowFlags flags) :
|
||||
QDockWidget(parent, flags) {
|
||||
QDialog(parent, flags | Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint) {
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
|
||||
// set as floating
|
||||
setFeatures(QDockWidget::DockWidgetFloatable);
|
||||
// handle rezize and move events
|
||||
parentWidget()->installEventFilter(this);
|
||||
|
||||
// remove titlebar
|
||||
setTitleBarWidget(new QWidget());
|
||||
// handle minimize, restore and focus events
|
||||
Application::getInstance()->installEventFilter(this);
|
||||
}
|
||||
|
||||
setAllowedAreas(Qt::LeftDockWidgetArea);
|
||||
bool FramelessDialog::eventFilter(QObject* sender, QEvent* event) {
|
||||
switch (event->type()) {
|
||||
case QEvent::Move:
|
||||
|
||||
if (sender == parentWidget()) {
|
||||
// move to upper left corner on app move
|
||||
move(parentWidget()->geometry().topLeft());
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::Resize:
|
||||
if (sender == parentWidget()) {
|
||||
// keep full app height on resizing the app
|
||||
setFixedHeight(parentWidget()->size().height());
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::WindowStateChange:
|
||||
if (parentWidget()->isMinimized()) {
|
||||
setHidden(true);
|
||||
} else {
|
||||
setHidden(false);
|
||||
}
|
||||
break;
|
||||
|
||||
case QEvent::ApplicationDeactivate:
|
||||
// hide on minimize and focus lost
|
||||
setHidden(true);
|
||||
break;
|
||||
|
||||
case QEvent::ApplicationActivate:
|
||||
setHidden(false);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
FramelessDialog::~FramelessDialog() {
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
void FramelessDialog::setStyleSheetFile(const QString& fileName) {
|
||||
|
@ -36,3 +75,33 @@ void FramelessDialog::setStyleSheetFile(const QString& fileName) {
|
|||
setStyleSheet(globalStyleSheet.readAll() + styleSheet.readAll());
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessDialog::showEvent(QShowEvent* event) {
|
||||
// move to upper left corner
|
||||
move(parentWidget()->geometry().topLeft());
|
||||
|
||||
// keep full app height
|
||||
setFixedHeight(parentWidget()->size().height());
|
||||
|
||||
// resize parrent if width is smaller than this dialog
|
||||
if (parentWidget()->size().width() < size().width()) {
|
||||
parentWidget()->resize(size().width(), parentWidget()->size().height());
|
||||
}
|
||||
}
|
||||
void FramelessDialog::mousePressEvent(QMouseEvent* mouseEvent) {
|
||||
if (abs(mouseEvent->pos().x() - size().width()) < RESIZE_HANDLE_WIDTH && mouseEvent->button() == Qt::LeftButton) {
|
||||
_isResizing = true;
|
||||
QApplication::setOverrideCursor(Qt::SizeHorCursor);
|
||||
}
|
||||
}
|
||||
|
||||
void FramelessDialog::mouseReleaseEvent(QMouseEvent* mouseEvent) {
|
||||
QApplication::restoreOverrideCursor();
|
||||
_isResizing = false;
|
||||
}
|
||||
|
||||
void FramelessDialog::mouseMoveEvent(QMouseEvent* mouseEvent) {
|
||||
if (_isResizing) {
|
||||
resize(mouseEvent->pos().x(), size().height());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,27 +9,29 @@
|
|||
#ifndef __hifi__FramelessDialog__
|
||||
#define __hifi__FramelessDialog__
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QDialog>
|
||||
#include <QGridLayout>
|
||||
#include <QString>
|
||||
#include <QPainter>
|
||||
#include <QStyleOptionTitleBar>
|
||||
#include <QtCore/QTimer>
|
||||
|
||||
class FramelessDialog : public QDockWidget {
|
||||
class FramelessDialog : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FramelessDialog(QWidget* parent = 0, Qt::WindowFlags flags = 0);
|
||||
~FramelessDialog();
|
||||
void setStyleSheetFile(const QString& fileName);
|
||||
|
||||
protected:
|
||||
/*
|
||||
virtual void mouseMoveEvent(QMouseEvent* mouseEvent);
|
||||
virtual void mousePressEvent(QMouseEvent* mouseEvent);
|
||||
virtual void mouseReleaseEvent(QMouseEvent* mouseEvent);
|
||||
*/
|
||||
|
||||
virtual void showEvent(QShowEvent* event);
|
||||
|
||||
bool eventFilter(QObject* sender, QEvent* event);
|
||||
|
||||
private:
|
||||
bool _isResizing;
|
||||
|
||||
|
|
Loading…
Reference in a new issue