mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 21:56:43 +08:00
refs #304, reflect changes in components for GUI, GUI utility class to set main window position correctly
This commit is contained in:
64
src/blackgui/guiutility.cpp
Normal file
64
src/blackgui/guiutility.cpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/* Copyright (C) 2014
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "guiutility.h"
|
||||
#include <QWidget>
|
||||
#include <QApplication>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
|
||||
QMainWindow *CGuiUtility::mainWindow()
|
||||
{
|
||||
QWidgetList tlw = topLevelApplicationWidgetsWithName();
|
||||
foreach(QWidget * w, tlw)
|
||||
{
|
||||
QMainWindow *mw = qobject_cast<QMainWindow *>(w);
|
||||
if (!mw) { continue; }
|
||||
QString n = mw->objectName().toLower();
|
||||
if (n.contains("main") && n.contains("window")) return mw;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
QWidgetList CGuiUtility::topLevelApplicationWidgetsWithName()
|
||||
{
|
||||
QWidgetList tlw = QApplication::topLevelWidgets();
|
||||
QWidgetList rl;
|
||||
foreach(QWidget * w, tlw)
|
||||
{
|
||||
if (w->objectName().isEmpty()) continue;
|
||||
rl.append(w);
|
||||
}
|
||||
return rl;
|
||||
}
|
||||
|
||||
QPoint CGuiUtility::mainWindowPosition()
|
||||
{
|
||||
QMainWindow *mw = mainWindow();
|
||||
return (mw) ? mw->pos() : QPoint();
|
||||
}
|
||||
|
||||
QPoint CGuiUtility::introWindowPosition()
|
||||
{
|
||||
QWidgetList tlw = topLevelApplicationWidgetsWithName();
|
||||
foreach(QWidget * w, tlw)
|
||||
{
|
||||
QString n = w->objectName().toLower();
|
||||
if (n.contains("intro")) return w->pos();
|
||||
}
|
||||
return QPoint(0, 0);
|
||||
}
|
||||
|
||||
QPoint CGuiUtility::assumedMainWindowPosition()
|
||||
{
|
||||
QPoint p = mainWindowPosition();
|
||||
return (p.isNull()) ? introWindowPosition() : p;
|
||||
}
|
||||
}
|
||||
48
src/blackgui/guiutility.h
Normal file
48
src/blackgui/guiutility.h
Normal file
@@ -0,0 +1,48 @@
|
||||
/* Copyright (C) 2014
|
||||
* swift Project Community / Contributors
|
||||
*
|
||||
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of Swift Project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_GUIUTILITY_H
|
||||
#define BLACKGUI_GUIUTILITY_H
|
||||
|
||||
#include <QWidgetList>
|
||||
#include <QMainWindow>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
//! GUI utilities
|
||||
class CGuiUtility
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
//! Main application window
|
||||
static QMainWindow *mainWindow();
|
||||
|
||||
//! Top level widgets with names
|
||||
static QWidgetList topLevelApplicationWidgetsWithName();
|
||||
|
||||
//! Position of main window
|
||||
static QPoint mainWindowPosition();
|
||||
|
||||
//! Position of intro window
|
||||
static QPoint introWindowPosition();
|
||||
|
||||
//! During initialization, when main window position might not be set set
|
||||
static QPoint assumedMainWindowPosition();
|
||||
|
||||
private:
|
||||
//! Constructor, use static methods only
|
||||
CGuiUtility() {}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // guard
|
||||
@@ -1,5 +1,9 @@
|
||||
/** http://qt-project.org/doc/qt-5.3/stylesheet-examples.html **/
|
||||
|
||||
#MainWindow {
|
||||
background-color: darkslategray;
|
||||
}
|
||||
|
||||
QWidget {
|
||||
background-color: black;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user