Skip to content

Commit 7a7daf1

Browse files
committed
first commit
1 parent 11ca044 commit 7a7daf1

9 files changed

+406
-0
lines changed

GetScreenGeometry.pro

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
QT += core gui
2+
3+
unix:!macx:{
4+
LIBS += -lX11
5+
}
6+
7+
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
8+
9+
TARGET = GetScreenGeometry
10+
TEMPLATE = app
11+
12+
DEFINES += QT_DEPRECATED_WARNINGS
13+
14+
SOURCES += \
15+
main.cpp \
16+
mainwindow.cpp
17+
18+
HEADERS += \
19+
mainwindow.h
20+
21+
FORMS += \
22+
mainwindow.ui
23+
24+
RC_ICONS = logo.ico
25+
26+
RESOURCES += \
27+
root.qrc

image-folder/Linux.gif

192 KB
Loading

image-folder/Windows.gif

151 KB
Loading

logo.ico

162 KB
Binary file not shown.

main.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#include "mainwindow.h"
2+
#include <QApplication>
3+
4+
int main(int argc, char *argv[])
5+
{
6+
QApplication a(argc, argv);
7+
MainWindow w;
8+
w.show();
9+
10+
return a.exec();
11+
}

mainwindow.cpp

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
#include "mainwindow.h"
2+
#include "ui_mainwindow.h"
3+
#include <QScreen>
4+
#include <QFileDialog>
5+
#include <QMessageBox>
6+
#include <QFile>
7+
#include <QTime>
8+
9+
#ifdef Q_OS_WIN
10+
#include "windows.h"
11+
#pragma comment(lib, "user32.lib")
12+
#endif
13+
14+
#ifdef Q_OS_LINUX
15+
#include <X11/Xlib.h>
16+
#endif
17+
18+
MainWindow::MainWindow(QWidget *parent) :
19+
QMainWindow(parent),
20+
ui(new Ui::MainWindow)
21+
{
22+
ui->setupUi(this);
23+
24+
m_timer = new QTimer(this);
25+
connect(m_timer, SIGNAL(timeout()), this, SLOT(update()));
26+
27+
m_nExecutionType = 0;
28+
m_nScreen_width = 0;
29+
m_nScreen_height = 0;
30+
}
31+
32+
MainWindow::~MainWindow()
33+
{
34+
delete ui;
35+
}
36+
37+
void MainWindow::on_pushButton_start_clicked()
38+
{
39+
m_timer->start(ui->spinBox_timer->value());
40+
}
41+
42+
void MainWindow::update()
43+
{
44+
QString strOprType = "";
45+
46+
switch (m_nExecutionType) {
47+
case 0:
48+
{
49+
QScreen* screen = QGuiApplication::primaryScreen();
50+
QRect mm = screen->availableGeometry();
51+
m_nScreen_width = mm.width();
52+
m_nScreen_height = mm.height();
53+
strOprType = "Qt API";
54+
break;
55+
}
56+
case 1:
57+
{
58+
#ifdef Q_OS_WIN
59+
m_nScreen_width = GetSystemMetrics(SM_CXSCREEN);
60+
m_nScreen_height = GetSystemMetrics(SM_CYSCREEN);
61+
strOprType = "Windows API";
62+
#endif
63+
break;
64+
}
65+
case 2:
66+
{
67+
#ifdef Q_OS_LINUX
68+
Display *display = XOpenDisplay(NULL);
69+
int screen_num = DefaultScreen(display);
70+
m_nScreen_width = XDisplayWidth(display,screen_num);
71+
m_nScreen_height = XDisplayHeight(display,screen_num);
72+
strOprType = "Linux API";
73+
#endif
74+
break;
75+
}
76+
default:
77+
break;
78+
}
79+
80+
QString str = QString("[%1]-> Width: %2, Height: %3 Operation:%4")
81+
.arg(getSystemTime())
82+
.arg(m_nScreen_width)
83+
.arg(m_nScreen_height)
84+
.arg(strOprType);
85+
86+
87+
ui->textEdit->append(str);
88+
}
89+
90+
void MainWindow::on_pushButton_clear_clicked()
91+
{
92+
ui->textEdit->clear();
93+
}
94+
95+
void MainWindow::on_pushButton_stop_clicked()
96+
{
97+
m_timer->stop();
98+
}
99+
100+
void MainWindow::on_pushButton_Qt_clicked()
101+
{
102+
m_nExecutionType = 0;
103+
}
104+
105+
void MainWindow::on_pushButton_Win_clicked()
106+
{
107+
m_nExecutionType = 1;
108+
}
109+
110+
void MainWindow::on_pushButton_Linux_clicked()
111+
{
112+
m_nExecutionType = 2;
113+
}
114+
115+
void MainWindow::on_pushButton_save_clicked()
116+
{
117+
QString filePath = QFileDialog::getSaveFileName(this, tr("Save Data"), "",
118+
tr("Data Files (*.txt)"));
119+
if (filePath.isNull())
120+
return;
121+
122+
QFile file(filePath);
123+
if (!file.open(QIODevice::WriteOnly|QIODevice::Text))
124+
{
125+
QMessageBox::information(this, QString("Hint"),
126+
QString(""));
127+
return;
128+
}
129+
QString data = ui->textEdit->toPlainText();
130+
file.write(data.toLatin1());
131+
}
132+
133+
QString MainWindow::getSystemTime()
134+
{
135+
QTime *time = new QTime();
136+
QString strTime;
137+
strTime = time->currentTime().toString("HH:mm:ss.zzz");
138+
return strTime;
139+
}
140+
141+
void MainWindow::on_spinBox_timer_valueChanged(int arg)
142+
{
143+
if(m_timer->isActive())
144+
m_timer->start(arg);
145+
}

mainwindow.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef MAINWINDOW_H
2+
#define MAINWINDOW_H
3+
4+
#include <QMainWindow>
5+
#include <QtGlobal>
6+
#include <QTimer>
7+
8+
namespace Ui {
9+
class MainWindow;
10+
}
11+
12+
class MainWindow : public QMainWindow
13+
{
14+
Q_OBJECT
15+
16+
public:
17+
explicit MainWindow(QWidget *parent = 0);
18+
~MainWindow();
19+
20+
private slots:
21+
void update();
22+
void on_pushButton_start_clicked();
23+
void on_pushButton_stop_clicked();
24+
void on_pushButton_Qt_clicked();
25+
void on_pushButton_Win_clicked();
26+
void on_pushButton_Linux_clicked();
27+
void on_pushButton_save_clicked();
28+
void on_pushButton_clear_clicked();
29+
QString getSystemTime();
30+
31+
void on_spinBox_timer_valueChanged(int arg);
32+
33+
34+
35+
private:
36+
Ui::MainWindow *ui;
37+
QTimer* m_timer;
38+
int m_nExecutionType;
39+
int m_nScreen_width;
40+
int m_nScreen_height;
41+
};
42+
43+
#endif // MAINWINDOW_H

0 commit comments

Comments
 (0)