forked from martyr-deepin/deepin-appstore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cpp
84 lines (71 loc) · 2.4 KB
/
MainWindow.cpp
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Copyright (C) 2015 Deepin Technology Co., Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
**/
#include "common.h"
#include <QDebug>
#include <QIcon>
#include <QLayout>
#include <QEvent>
#include <QKeyEvent>
#include "Shell.h"
#include "MainWindow.h"
#include "FilterMouseMove.h"
MainWindow::MainWindow(StupidWindow *parent) : StupidWindow(parent) {
qDebug() << "Build with" << WebWidgetName;
this->setWindowIcon(QIcon::fromTheme("deepin-appstore"));
this->resize(1028, 700);
this->setMinimumSize(906, 680);
this->setMouseTracking(true);
this->setAttribute(Qt::WA_QuitOnClose, true);
this->setAttribute(Qt::WA_DeleteOnClose, true);
this->webView = new WebView(this);
// Leave event will cause problems with <horizontal-resizer>, eat leave events!
const auto filter = new FilterMouseMove(this);
this->webView->installEventFilter(filter);
connect(this->webView, &WebView::titleChanged, [this](const QString& title) {
if (!title.isEmpty()) {
this->setWindowTitle(title);
// disconnect(this->webView, &WebView::titleChanged, nullptr, nullptr);
}
});
this->layout()->addWidget(this->webView);
}
void MainWindow::toggleMaximized() {
if (this->isMaximized()) {
this->showNormal();
} else {
this->showMaximized();
}
}
void MainWindow::changeEvent(QEvent *event) {
StupidWindow::changeEvent(event);
if (event->type() == QEvent::WindowStateChange) {
emit this->windowStateChanged((Qt::WindowState)(int)this->windowState());
}
}
void MainWindow::setUrl(const QUrl &url) {
this->webView->setUrl(url);
}
void MainWindow::keyPressEvent(QKeyEvent* event) {
if (event->key() == Qt::Key_F1 &&
event->modifiers() == Qt::NoModifier) {
const auto shell = static_cast<Shell*>(qApp);
shell->openManual();
};
}
MainWindow::~MainWindow() {
}
bool MainWindow::event(QEvent* event) {
if (event->type() == QEvent::WindowDeactivate) {
// Try hard to kill tooltips
// https://bugzilla.deepin.io/show_bug.cgi?id=4351
const auto shell = static_cast<Shell*>(qApp);
shell->showTooltip("", QRect());
}
return QWidget::event(event);
}