11 #include <QMouseEvent>
14 #include <QPushButton>
34 bool isMainApplicationWindow,
35 const char *framelessPropertyName,
36 QWidget *correspondingWidget)
37 : m_windowMode(mode), m_isMainApplicationWindow(isMainApplicationWindow), m_widget(correspondingWidget),
38 m_framelessPropertyName(framelessPropertyName)
40 Q_ASSERT(correspondingWidget);
62 if (isFrameless == frameless) {
return; }
66 const QRect oldFrameGeometry = w->frameGeometry();
67 const QRect oldGeometry = w->geometry();
70 if (nonFrameLessMode == WindowFrameless) { nonFrameLessMode = WindowNormal; }
71 this->
setMode(frameless ? WindowFrameless : nonFrameLessMode);
76 w->setGeometry(oldFrameGeometry);
84 QRect newGeometry = oldGeometry;
89 w->setGeometry(newGeometry);
96 Qt::WindowFlags flags =
m_widget->windowFlags();
97 if (onTop) { flags |= Qt::WindowStaysOnTopHint; }
98 else { flags &= ~Qt::WindowStaysOnTopHint; }
106 m_widget->setWindowState(Qt::WindowActive);
111 const QString ws(s.trimmed().toLower());
112 if (ws.isEmpty()) {
return WindowNormal; }
113 if (ws.contains(
"frameless") || ws.startsWith(
"f")) {
return WindowFrameless; }
114 if (ws.contains(
"tool") || ws.startsWith(
"t")) {
return WindowTool; }
120 static const QString n(
"normal");
121 static const QString f(
"frameless");
122 static const QString t(
"tool");
126 case WindowFrameless:
return f;
127 case WindowNormal:
return n;
128 case WindowTool:
return t;
141 Q_ASSERT_X(
m_widget,
"CEnableForFramelessWindow::setWindowAttributes",
"Missing widget representing window");
143 "Missing property name");
145 const bool frameless = (mode == WindowFrameless);
152 m_widget->setAttribute(Qt::WA_NativeWindow);
155 m_widget->setAttribute(Qt::WA_NoSystemBackground, frameless);
156 m_widget->setAttribute(Qt::WA_TranslucentBackground, frameless);
167 Q_ASSERT_X(
m_widget,
"CEnableForFramelessWindow::setDynamicProperties",
"Missing widget representing window");
169 "Missing property name");
174 for (QObject *w :
m_widget->children())
195 if (
m_windowMode == WindowFrameless && event->button() == Qt::LeftButton)
229 if (event->type() != QEvent::WindowStateChange) {
return false; }
237 QPointer<QWidget> widgetSelf(
m_widget);
244 if (!widgetSelf) {
return; }
253 if (!widgetSelf) {
return; }
263 if (!statusBar) {
return; }
271 statusBar->repaint();
292 Qt::QueuedConnection);
295 QHBoxLayout *menuBarLayout =
new QHBoxLayout;
296 menuBarLayout->setObjectName(
"hl_MenuBar");
297 menuBarLayout->addWidget(menuBar, 0, Qt::AlignTop | Qt::AlignLeft);
299 return menuBarLayout;
304 m_widget->setWindowFlags((
m_widget->windowFlags() & (~Qt::Tool)) | Qt::Window);
322 case WindowFrameless:
return (Qt::Window | Qt::FramelessWindowHint);
326 return (Qt::Tool | Qt::WindowMinimizeButtonHint | Qt::WindowCloseButtonHint);
329 return (Qt::Window | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint |
330 Qt::WindowCloseButtonHint);
int m_windowFrameSizeH
window frame height
QWidget * getWidget() const
Corresponding QMainWindow.
bool handleMousePressEvent(QMouseEvent *event)
Mouse press, required for frameless window.
void setMode(WindowMode mode)
Window mode.
void addFramelessSizeGripToStatusBar(QStatusBar *statusBar)
Resize grip handle.
static Qt::WindowFlags modeToWindowFlags(WindowMode mode)
Translate mode.
void showMinimizedModeChecked()
Check mode and then show minimized.
static WindowMode stringToWindowMode(const QString &s)
String to window mode.
bool isToolWindow() const
Tool window.
virtual void windowFlagsChanged()
Can be used as notification if window mode changes.
void hideFramelessSizeGripInStatusBar()
Resize grip handle.
virtual void setFrameless(bool frameless)
Framless.
static const QString & windowModeToString(WindowMode m)
String to window mode.
QPoint m_framelessDragPosition
position, if moving is handled with frameless window
bool m_isMainApplicationWindow
is this the main application window (only 1)?
void setWindowAttributes(WindowMode mode)
Attributes.
bool handleChangeEvent(QEvent *event)
Mouse window change event.
WindowMode m_windowMode
Window mode,.
WindowMode m_originalWindowMode
mode when initialized
QByteArray m_framelessPropertyName
property name for frameless widgets
void toolToNormalWindow()
Remove tool and add desktop window.
QHBoxLayout * addFramelessCloseButton(QMenuBar *menuBar)
Close button for frameless windows.
void showNormalModeChecked()
Check mode and then show normal.
int m_windowFrameSizeW
window frame width
bool handleMouseMoveEvent(QMouseEvent *event)
Mouse moving, required for frameless window.
void activate()
Activates the window.
QPushButton * m_framelessCloseButton
close button
QSizeGrip * m_framelessSizeGrip
size grip object
QSize m_moveSize
size when moved (in frameless window)
void alwaysOnTop(bool onTop)
Always on top?
bool isFrameless() const
Frameless?
void normalToToolWindow()
Remove desktop and add tool window.
QWidget * m_widget
corresponding window or dock widget
void setDynamicProperties(bool frameless)
Set dynamic properties such as frameless.
static bool isTopLevelWindow(QWidget *widget)
Is top level window?
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToTrueFalse(bool v)
Bool to true/false.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...