-
Notifications
You must be signed in to change notification settings - Fork 2
/
mainwindow.cpp
98 lines (82 loc) · 2.53 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright (C) 2018 Microchip Technology Inc. All rights reserved.
* Joshua Henderson <joshua.henderson@microchip.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <QApplication>
#include <QKeyEvent>
#include <QLabel>
#include <QPushButton>
#include <QVBoxLayout>
#include "mainwindow.h"
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
m_whiteboard = new WhiteBoard;
QVBoxLayout *vlay = new QVBoxLayout(m_whiteboard);
QPushButton *btn1 = new QPushButton(" ");
QPalette pal = btn1->palette();
pal.setColor(QPalette::Button, QColor(Qt::blue));
btn1->setAutoFillBackground(true);
btn1->setPalette(pal);
btn1->update();
vlay->addWidget(btn1, 0, Qt::AlignRight);
QPushButton *btn2 = new QPushButton(" ");
pal = btn2->palette();
pal.setColor(QPalette::Button, QColor(Qt::red));
btn2->setAutoFillBackground(true);
btn2->setPalette(pal);
btn2->update();
vlay->addWidget(btn2, 0, Qt::AlignRight);
QPushButton *btn3 = new QPushButton(" ");
pal = btn3->palette();
pal.setColor(QPalette::Button, QColor(Qt::green));
btn3->setAutoFillBackground(true);
btn3->setPalette(pal);
btn3->update();
vlay->addWidget(btn3, 0, Qt::AlignRight);
QPushButton *btn4 = new QPushButton("Clear");
pal = btn4->palette();
pal.setColor(QPalette::Button, QColor(Qt::white));
btn4->setAutoFillBackground(true);
btn4->setPalette(pal);
btn4->update();
vlay->addWidget(btn4, 0, Qt::AlignRight);
m_whiteboard->setLayout(vlay);
setCentralWidget(m_whiteboard);
QPixmap image(":/images/logo.png");
QLabel* logo = new QLabel(this);
logo->setGeometry(10, 10, image.width() * (800 / width()), image.height() * (480 / height()));
logo->setPixmap(image.scaled(logo->width(), logo->height(), Qt::KeepAspectRatio));
connect(btn1, SIGNAL (pressed()), this, SLOT(setPenBlue()));
connect(btn2, SIGNAL (pressed()), this, SLOT(setPenRed()));
connect(btn3, SIGNAL (pressed()), this, SLOT(setPenGreen()));
connect(btn4, SIGNAL (pressed()), this, SLOT(clearScreen()));
}
void MainWindow::setPenBlue()
{
m_whiteboard->setPenColor(Qt::blue);
}
void MainWindow::setPenRed()
{
m_whiteboard->setPenColor(Qt::red);
}
void MainWindow::setPenGreen()
{
m_whiteboard->setPenColor(Qt::green);
}
void MainWindow::clearScreen()
{
m_whiteboard->clearImage();
}
void MainWindow::keyPressEvent(QKeyEvent* k)
{
if (k->key() == Qt::Key_0)
{
QApplication::instance()->exit();
}
}
MainWindow::~MainWindow()
{
}