Debian Codegraph @

src/gui/windowResizer/WindowResizer.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 2021 Damir Porobic <[email protected]>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "WindowResizer.h"
21
22 WindowResizer::WindowResizer(IResizableWindow *resizableWindow, const QSharedPointer<IConfig> &config, QObject *parent) :
23 QObject(parent),
24 mResizableWindow(resizableWindow),
25 mConfig(config),
26 mPerformedAutoResize(false),
27 mResizeDelayInMs(50)
28 {
29 Q_ASSERT(mResizableWindow != nullptr);
30 Q_ASSERT(mConfig != nullptr);
31 }
32
33 void WindowResizer::resize()
34 {
35 if(mResizableWindow->isWindowMaximized()) {
36 return;
37 }
38
39 auto enforceAutoResize = mConfig->autoResizeToContent() || !mPerformedAutoResize;
40 if (enforceAutoResize) {
41 QTimer::singleShot(mConfig->resizeToContentDelay(), this, &WindowResizer::resizeWindow);
42 }
43 }
44
45 void WindowResizer::resetAndResize()
46 {
47 mPerformedAutoResize = false;
48 resize();
49 }
50
51 void WindowResizer::resizeWindow()
52 {
53 mPerformedAutoResize = true;
54 mResizableWindow->resizeToContent();
55 }