kwave  18.07.70
MultiStateWidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  MultiStateWidget.cpp - provides methods of multistateWidget a Class that
3  switches the image it, displays on clicking, used
4  for the channel enable/disable lamps...
5  -------------------
6  begin : Sun Jun 04 2000
7  copyright : (C) 2000 by Martin Wilz
8  email : martin@wilz.de
9  ***************************************************************************/
10 
11 /***************************************************************************
12  * *
13  * This program is free software; you can redistribute it and/or modify *
14  * it under the terms of the GNU General Public License as published by *
15  * the Free Software Foundation; either version 2 of the License, or *
16  * (at your option) any later version. *
17  * *
18  ***************************************************************************/
19 #include "config.h"
20 
21 #include <QDir>
22 #include <QMouseEvent>
23 #include <QPainter>
24 #include <QStandardPaths>
25 #include <QString>
26 
27 #include "libkwave/String.h"
28 
30 
31 //***************************************************************************
33  :QWidget(parent), m_current_index(0), m_identifier(id), m_pixmaps()
34 {
35  resize(20, 20);
36 }
37 
38 //***************************************************************************
40 {
41  m_pixmaps.clear();
42 }
43 
44 //***************************************************************************
46 {
47  m_identifier = id;
48 }
49 
50 //***************************************************************************
51 void Kwave::MultiStateWidget::addPixmap(const QString &filename)
52 {
53  QString pics_dir = _("pics");
54  QString path = QStandardPaths::locate(
55  QStandardPaths::AppDataLocation,
56  pics_dir + QDir::separator() + filename,
57  QStandardPaths::LocateFile);
58  QPixmap newpix(path);
59  m_pixmaps.append(newpix);
60 }
61 
62 //***************************************************************************
64 {
65  m_current_index = (state % m_pixmaps.count());
66  repaint();
67 }
68 
69 //***************************************************************************
71 {
72  setState((on) ? 1 : 0);
73 }
74 
75 //***************************************************************************
77 {
79  emit clicked(m_identifier);
80 }
81 
82 //***************************************************************************
84 {
85  if (e && (e->button() == Qt::LeftButton)) {
86  nextState();
87  }
88 }
89 
90 //***************************************************************************
92 {
93  QPainter p(this);
94  p.drawPixmap(0, 0, m_pixmaps[m_current_index]);
95 }
96 
97 //***************************************************************************
98 //***************************************************************************
void setState(int newstate)
virtual ~MultiStateWidget() Q_DECL_OVERRIDE
QVector< QPixmap > m_pixmaps
void addPixmap(const QString &filename)
virtual void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE
virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE
MultiStateWidget(QWidget *parent, int id)
#define _(m)
Definition: memcpy.c:66