kwave  18.07.70
Kwave::Splash Class Reference

#include <Splash.h>

Inheritance diagram for Kwave::Splash:
Inheritance graph
Collaboration diagram for Kwave::Splash:
Collaboration graph

Public Member Functions

 Splash (const QString &PNGFile)
 
virtual ~Splash () Q_DECL_OVERRIDE
 
virtual void paintEvent (QPaintEvent *e) Q_DECL_OVERRIDE
 
virtual void mousePressEvent (QMouseEvent *) Q_DECL_OVERRIDE
 
void done ()
 

Static Public Member Functions

static void showMessage (const QString &message)
 

Private Attributes

QFont m_font
 
QPixmap m_pixmap
 
QString m_message
 

Static Private Attributes

static QPointer< Kwave::Splashm_splash = Q_NULLPTR
 

Detailed Description

Definition at line 34 of file Splash.h.

Constructor & Destructor Documentation

◆ Splash()

Kwave::Splash::Splash ( const QString &  PNGFile)
explicit

Constructor

Parameters
PNGFilename of a file to be shown as splashscreen, should be found in one of the "appdata" directories.

Definition at line 42 of file Splash.cpp.

References background, m_font, m_pixmap, m_splash, and rect().

43  :QFrame(Q_NULLPTR, Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint),
44  m_font(),
45  m_pixmap(QStandardPaths::locate(QStandardPaths::DataLocation, PNGFile)),
46  m_message(_(" "))
47 {
48  const int w = m_pixmap.width();
49  const int h = m_pixmap.height();
50  setFixedSize(w, h);
51 
52  QPainter p;
53  p.begin(&m_pixmap);
54 
55  // get all the strings that we should display
56  const KAboutData about_data = KAboutData::applicationData();
57  QString version = i18nc("%1=Version number", "v%1", about_data.version());
58 
59  m_font.setBold(true);
60  m_font.setStyleHint(QFont::Decorative);
61  m_font.setWeight(QFont::Black);
62  p.setFont(m_font);
63 
64  QFontMetrics fm(m_font);
65  QRect rect = fm.boundingRect(version);
66 
67  // version
68  const int r = 5;
69  const int th = rect.height();
70  const int tw = rect.width();
71  const int x = w - 10 - tw;
72  const int y = h - 10 - th;
73 
74  const QBrush brush(palette().background().color());
75  p.setBrush(brush);
76  p.setOpacity(0.50);
77  p.setPen(Qt::NoPen);
78  p.drawRoundRect(
79  x - r, y - r,
80  tw + 2 * r, th + (2 * r),
81  (200 * r) / th, (200 * r) / th
82  );
83 
84  p.setOpacity(1.0);
85  p.setPen(palette().buttonText().color());
86  p.drawText(x, y, tw, th, Qt::AlignCenter, version);
87 
88  p.end();
89 
90  // center on the screen
91  rect = QRect(QPoint(), m_pixmap.size());
92  resize(rect.size());
93  move(QApplication::desktop()->screenGeometry().center() - rect.center());
94 
95  m_splash = this;
96 }
QString m_message
Definition: Splash.h:70
static QPointer< Kwave::Splash > m_splash
Definition: Splash.h:73
QPixmap m_pixmap
Definition: Splash.h:67
static const char * background[]
#define _(m)
Definition: memcpy.c:66
QFont m_font
Definition: Splash.h:64
static double rect(double param)
Definition: Functions.cpp:29
Here is the call graph for this function:

◆ ~Splash()

Kwave::Splash::~Splash ( )
virtual

Destructor

Definition at line 109 of file Splash.cpp.

References m_splash.

110 {
111  m_splash = Q_NULLPTR;
112 }
static QPointer< Kwave::Splash > m_splash
Definition: Splash.h:73

Member Function Documentation

◆ done()

void Kwave::Splash::done ( )

should be called when the splashscreen is no longer needed

Definition at line 99 of file Splash.cpp.

References m_splash.

Referenced by main(), and mousePressEvent().

100 {
101  // check: start() must be called from the GUI thread only!
102  Q_ASSERT(this->thread() == QThread::currentThread());
103  Q_ASSERT(this->thread() == qApp->thread());
104  m_splash = Q_NULLPTR;
105  hide();
106 }
static QPointer< Kwave::Splash > m_splash
Definition: Splash.h:73
Here is the caller graph for this function:

◆ mousePressEvent()

void Kwave::Splash::mousePressEvent ( QMouseEvent *  )
virtual

hides the splash screen on mouse click

Definition at line 150 of file Splash.cpp.

References done().

151 {
152  done();
153 }
void done()
Definition: Splash.cpp:99
Here is the call graph for this function:

◆ paintEvent()

void Kwave::Splash::paintEvent ( QPaintEvent *  e)
virtual

handles the painting of this splash screen

Definition at line 124 of file Splash.cpp.

References m_font, m_message, m_pixmap, m_splash, and rect().

125 {
126  // special handling: a null message tells us to hide
127  if (!m_message.length()) {
128  m_splash = Q_NULLPTR;
129  hide();
130  return;
131  }
132 
133  QRect rect(this->rect());
134  const int border = 5;
135  rect.setRect(
136  rect.x() + border,
137  rect.y() + border,
138  rect.width() - (2 * border),
139  rect.height() - (2 * border)
140  );
141 
142  QPainter p(this);
143  p.drawPixmap(this->rect(), m_pixmap);
144  p.setFont(m_font);
145  p.setPen(palette().buttonText().color());
146  p.drawText(rect, Qt::AlignLeft | Qt::AlignTop, m_message);
147 }
QString m_message
Definition: Splash.h:70
static QPointer< Kwave::Splash > m_splash
Definition: Splash.h:73
QPixmap m_pixmap
Definition: Splash.h:67
QFont m_font
Definition: Splash.h:64
static double rect(double param)
Definition: Functions.cpp:29
Here is the call graph for this function:

◆ showMessage()

void Kwave::Splash::showMessage ( const QString &  message)
static

wrapper for QSplashScreen::showMessage with only one parameter

Definition at line 115 of file Splash.cpp.

References m_splash.

Referenced by Kwave::FileContext::init(), Kwave::TopWidget::loadFile(), Kwave::App::newInstance(), Kwave::App::newWindow(), and Kwave::TopWidget::showInSplashSreen().

116 {
117  if (!m_splash) return;
118  m_splash->m_message = message;
119  m_splash->repaint();
120  QApplication::processEvents(QEventLoop::AllEvents);
121 }
static QPointer< Kwave::Splash > m_splash
Definition: Splash.h:73
Here is the caller graph for this function:

Member Data Documentation

◆ m_font

QFont Kwave::Splash::m_font
private

font to use for the status text and version number

Definition at line 64 of file Splash.h.

Referenced by paintEvent(), and Splash().

◆ m_message

QString Kwave::Splash::m_message
private

last status message

Definition at line 70 of file Splash.h.

Referenced by paintEvent().

◆ m_pixmap

QPixmap Kwave::Splash::m_pixmap
private

pixmap with the Kwave logo

Definition at line 67 of file Splash.h.

Referenced by paintEvent(), and Splash().

◆ m_splash

QPointer< Kwave::Splash > Kwave::Splash::m_splash = Q_NULLPTR
staticprivate

static instance

Definition at line 73 of file Splash.h.

Referenced by done(), paintEvent(), showMessage(), Splash(), and ~Splash().


The documentation for this class was generated from the following files: