1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #include "textedittitlebar.h" |
6 | |
7 | #include <QMap> |
8 | #include <QPainter> |
9 | #include <QHBoxLayout> |
10 | #include <QVBoxLayout> |
11 | #include <QDebug> |
12 | |
13 | class TextEditTitleBarPrivate |
14 | { |
15 | friend class TextEditTitleBar; |
16 | QLabel infoLabel; |
17 | QColor background; |
18 | QMap<TextEditTitleBar::StandardButton, QPushButton *> buttons; |
19 | }; |
20 | |
21 | TextEditTitleBar::TextEditTitleBar(QWidget *parent) |
22 | : QStatusBar(parent), d(new TextEditTitleBarPrivate) |
23 | { |
24 | } |
25 | |
26 | TextEditTitleBar::~TextEditTitleBar() |
27 | { |
28 | if (d) { |
29 | for (auto button : d->buttons.values()) { |
30 | delete button; |
31 | } |
32 | d->buttons.clear(); |
33 | delete d; |
34 | } |
35 | } |
36 | |
37 | QPushButton *TextEditTitleBar::button(TextEditTitleBar::StandardButton button) |
38 | { |
39 | return d->buttons[button]; |
40 | } |
41 | |
42 | TextEditTitleBar *TextEditTitleBar::changedReload(const QString &filePath) |
43 | { |
44 | auto self = new TextEditTitleBar(); |
45 | self->d->infoLabel.setText( |
46 | QLabel::tr("File Path: %0" ).arg(filePath) |
47 | + "\n" |
48 | + QLabel::tr("The current file has changed. Do you want to reload the current file?" )); |
49 | self->d->buttons[StandardButton::Reload] = new QPushButton(QPushButton::tr("Reload" )); |
50 | self->d->buttons[StandardButton::Cancel] = new QPushButton(QPushButton::tr("Cancel" )); |
51 | self->d->background = QColor(0xff0000); |
52 | self->setAutoFillBackground(true); |
53 | |
54 | connect(self->d->buttons[StandardButton::Reload], &QPushButton::clicked, [=](){ |
55 | self->reloadfile(); |
56 | self->close(); |
57 | }); |
58 | |
59 | connect(self->d->buttons[StandardButton::Cancel], &QPushButton::clicked, [=](){ |
60 | self->close(); |
61 | }); |
62 | |
63 | self->addWidget(&(self->d->infoLabel), 0); |
64 | for (auto button : self->d->buttons) { |
65 | button->setFixedSize(60, 30); |
66 | self->addWidget(button); |
67 | } |
68 | |
69 | QPalette palette; |
70 | palette.setBrush(QPalette::ColorRole::Window, QBrush(self->d->background)); |
71 | self->setPalette(palette); |
72 | return self; |
73 | } |
74 | |