dialog position fix

This commit is contained in:
shun_iwasawa 2016-11-14 15:56:58 +09:00
parent d6e3ed1575
commit 4ada6a9de4
2 changed files with 19 additions and 10 deletions

View file

@ -569,17 +569,16 @@ void LevelNameLineEdit::onEditingFinished() {
//=============================================================================
PencilTestPopup::PencilTestPopup()
: Dialog(TApp::instance()->getMainWindow(), false, false, "PencilTest")
, m_currentCamera(NULL)
, m_cameraImageCapture(NULL)
, m_captureWhiteBGCue(false)
, m_captureCue(false) {
// set the parent 0 in order to enable the popup behind the main window
: Dialog(0, false, false, "PencilTest"),
m_currentCamera(NULL),
m_cameraImageCapture(NULL),
m_captureWhiteBGCue(false),
m_captureCue(false) {
setWindowTitle(tr("Camera Capture"));
// add maximize button to the dialog
Qt::WindowFlags flags = windowFlags();
flags |= Qt::WindowMaximizeButtonHint;
setWindowFlags(flags);
setWindowFlags(windowFlags() | Qt::WindowMaximizeButtonHint);
layout()->setSizeConstraint(QLayout::SetNoConstraint);
@ -1241,6 +1240,7 @@ void PencilTestPopup::hideEvent(QHideEvent* event) {
if (m_currentCamera->state() == QCamera::LoadedState)
m_currentCamera->unload();
}
Dialog::hideEvent(event);
}
//-----------------------------------------------------------------------------

View file

@ -25,6 +25,7 @@
#include <QPainter>
#include <QRadioButton>
#include <QThread>
#include <QDesktopWidget>
// boost includes
#include <boost/algorithm/cxx11/any_of.hpp>
@ -286,8 +287,16 @@ Dialog::Dialog(QWidget *parent, bool hasButton, bool hasFixedSize,
if (geo != QString()) {
QStringList values = geo.split(" ");
assert(values.size() == 4);
setGeometry(values.at(0).toInt(), std::max(30, values.at(1).toInt()),
values.at(2).toInt(), values.at(3).toInt());
// Ensure that the dialog is visible in the screen.
// The dialog opens with some offset to bottom-right direction
// if a flag Qt::WindowMaximizeButtonHint is set. (e.g. PencilTestPopup)
// Therefore, if the dialog is moved to the bottom-end of the screen,
// it will be got out of the screen on the next launch.
// The following position adjustment will also prevent such behavior.
QRect screen = QApplication::desktop()->screenGeometry();
int x = std::min(values.at(0).toInt(), screen.width() - 50);
int y = std::min(std::max(30, values.at(1).toInt()), screen.height() - 90);
setGeometry(x, y, values.at(2).toInt(), values.at(3).toInt());
}
}