File: dialogsizehandler.cpp

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (64 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include "dialogsizehandler.h"
#include "services/config.h"
#include <QEvent>
#include <QTimer>
#include <QWidget>
#include <QScreen>
#include <QGuiApplication>
#include <QDebug>

DialogSizeHandler::DialogSizeHandler(QObject *parent) :
    DialogSizeHandler(parent->objectName(), parent)
{
}

DialogSizeHandler::DialogSizeHandler(const QString &key, QObject *parent) :
    QObject(parent), configKey(key)
{
    saveTimer = new QTimer(this);
    saveTimer->setInterval(500);
    saveTimer->setSingleShot(true);
    connect(saveTimer, SIGNAL(timeout()), this, SLOT(doSave()));

    QRect geom = CFG->get(CONFIG_GROUP, configKey).toRect();
    if (geom.isValid() && qApp->primaryScreen()->geometry().contains(geom))
    {
        QWidget* w = qobject_cast<QWidget*>(parent);
        w->setGeometry(geom);
    }
}

DialogSizeHandler::~DialogSizeHandler()
{
}

void DialogSizeHandler::applyFor(QObject *parent)
{
    QString key = parent->objectName();
    if (key.isEmpty())
        key = parent->metaObject()->className();

    applyFor(key, parent);
}

void DialogSizeHandler::applyFor(const QString &key, QObject *parent)
{
    DialogSizeHandler* handler = new DialogSizeHandler(key, parent);
    parent->installEventFilter(handler);
}

bool DialogSizeHandler::eventFilter(QObject *obj, QEvent *event)
{
    if (event->type() == QEvent::Resize || event->type() == QEvent::Move)
    {
        QWidget* w = qobject_cast<QWidget*>(obj);
        recentGeometry = w->geometry();
        saveTimer->start();
    }
    return false;
}

void DialogSizeHandler::doSave()
{
    CFG->set(CONFIG_GROUP, configKey, recentGeometry);
}