Freeciv21
Develop your civilization from humble roots to a global empire
report_widget.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Freeciv21 and Freeciv contributors
3  * SPDX-FileCopyrightText: Louis Moureaux <m_louis30@yahoo.com>
4  *
5  * SPDX-License-Identifier: GPLv3-or-later
6  */
7 
9 
10 // client
11 #include "fc_client.h"
12 #include "fonts.h"
13 #include "views/view_map.h"
14 
15 // Qt
16 #include <QApplication>
17 #include <QGridLayout>
18 #include <QMouseEvent>
19 
20 namespace freeciv {
21 
31 report_widget::report_widget(const QString &caption, const QString &headline,
32  const QString &lines, QWidget *parent)
33  : fcwidget(), m_caption(caption), m_headline(headline)
34 {
35  setAttribute(Qt::WA_DeleteOnClose);
36  setAttribute(Qt::WA_NoMousePropagation);
37  setCursor(Qt::ArrowCursor);
38  setParent(parent);
39  setFrameStyle(QFrame::Box);
40 
41  auto layout = new QGridLayout;
42  setLayout(layout);
43 
44  m_contents =
45  new QLabel(QStringLiteral("%1 %2\n%3").arg(caption, headline, lines));
46  m_contents->setTextInteractionFlags(Qt::TextSelectableByMouse);
47  m_contents->setFont(fcFont::instance()->getFont(
48  QStringLiteral("gui_qt_font_notify_label")));
49  layout->addWidget(m_contents, 0, 0);
50 
51  adjustSize();
52 
53  auto cw = new close_widget(this);
54  cw->setFixedSize(12, 12);
55  cw->put_to_corner();
56 }
57 
62 {
63  m_cursor = event->globalPos() - geometry().topLeft();
64 }
65 
70 {
71  move(event->globalPos() - m_cursor);
72  setCursor(Qt::SizeAllCursor);
73 }
74 
79 {
80  Q_UNUSED(event)
81  setCursor(Qt::ArrowCursor);
82 }
83 
88 {
89  if (event->type() == QEvent::FontChange) {
90  m_contents->setFont(fcFont::instance()->getFont(
91  QStringLiteral("gui_qt_font_notify_label")));
92  adjustSize();
93  event->accept();
94  return true;
95  }
96  return fcwidget::event(event);
97 }
98 
102 void report_widget::update_menu() { deleteLater(); }
103 
104 } // namespace freeciv
static fcFont * instance()
Returns instance of fc_font.
Definition: fonts.cpp:34
void mouseReleaseEvent(QMouseEvent *event) override
Reimplemented to let the user drag the widget.
report_widget(const QString &caption, const QString &headline, const QString &lines, QWidget *parent=nullptr)
Creates a report widget displaying the provided text.
void mousePressEvent(QMouseEvent *event) override
Reimplemented to let the user drag the widget.
void mouseMoveEvent(QMouseEvent *event) override
Reimplemented to let the user drag the widget.
void update_menu() override
Called when the close button is pressed.
QString headline() const
Returns back the headline passed to the constructor.
Definition: report_widget.h:32
QString caption() const
Returns back the caption passed to the constructor.
Definition: report_widget.h:29
bool event(QEvent *event) override
Overridden to handle font changes.
enum event_type event
Definition: events.cpp:68
Definition: path.cpp:10
char * caption
Definition: packhand.cpp:129
char * headline
Definition: packhand.cpp:130
char * lines
Definition: packhand.cpp:131