kwave  18.07.70
Kwave::MultiStateWidget Class Reference

#include <MultiStateWidget.h>

Inheritance diagram for Kwave::MultiStateWidget:
Inheritance graph
Collaboration diagram for Kwave::MultiStateWidget:
Collaboration graph

Public Slots

void setState (int newstate)
 
void switchState (bool on)
 
void nextState ()
 

Signals

void clicked (int id)
 

Public Member Functions

 MultiStateWidget (QWidget *parent, int id)
 
virtual ~MultiStateWidget () Q_DECL_OVERRIDE
 
void setID (int id)
 
void addPixmap (const QString &filename)
 

Private Member Functions

virtual void mouseReleaseEvent (QMouseEvent *) Q_DECL_OVERRIDE
 
virtual void paintEvent (QPaintEvent *) Q_DECL_OVERRIDE
 

Private Attributes

int m_current_index
 
int m_identifier
 
QVector< QPixmap > m_pixmaps
 

Detailed Description

Definition at line 36 of file MultiStateWidget.h.

Constructor & Destructor Documentation

◆ MultiStateWidget()

Kwave::MultiStateWidget::MultiStateWidget ( QWidget *  parent,
int  id 
)

Constructor

Parameters
parentthe parent widget
ididentifier

Definition at line 32 of file MultiStateWidget.cpp.

33  :QWidget(parent), m_current_index(0), m_identifier(id), m_pixmaps()
34 {
35  resize(20, 20);
36 }
QVector< QPixmap > m_pixmaps

◆ ~MultiStateWidget()

Kwave::MultiStateWidget::~MultiStateWidget ( )
virtual

Destructor

Definition at line 39 of file MultiStateWidget.cpp.

References m_pixmaps.

40 {
41  m_pixmaps.clear();
42 }
QVector< QPixmap > m_pixmaps

Member Function Documentation

◆ addPixmap()

void Kwave::MultiStateWidget::addPixmap ( const QString &  filename)

Adds a the content of pixmap file as pixmap for the next state. The file is found through the KStandardDirs mechanism. Adding a file for a second or further time is not possible, in this case the pixmap will not be loaded and the return value will be the id of the existing version.

See also
KStandardDirs
Parameters
filenamename of the file to be added, without path.

Definition at line 51 of file MultiStateWidget.cpp.

References _, and m_pixmaps.

Referenced by Kwave::TrackView::TrackView().

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 }
QVector< QPixmap > m_pixmaps
#define _(m)
Definition: memcpy.c:66
Here is the caller graph for this function:

◆ clicked

void Kwave::MultiStateWidget::clicked ( int  id)
signal

Signals that the widget has changed it's state.

Parameters
ididentifier of this widget's instance

Referenced by nextState().

Here is the caller graph for this function:

◆ mouseReleaseEvent()

void Kwave::MultiStateWidget::mouseReleaseEvent ( QMouseEvent *  e)
privatevirtual

reacts to the mouse release (click)

Definition at line 83 of file MultiStateWidget.cpp.

References nextState().

84 {
85  if (e && (e->button() == Qt::LeftButton)) {
86  nextState();
87  }
88 }
Here is the call graph for this function:

◆ nextState

void Kwave::MultiStateWidget::nextState ( )
slot

advance to the next state, with wrap-around to zero

Definition at line 76 of file MultiStateWidget.cpp.

References clicked(), m_current_index, m_identifier, and setState().

Referenced by mouseReleaseEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ paintEvent()

void Kwave::MultiStateWidget::paintEvent ( QPaintEvent *  )
privatevirtual

repaints the pixmap

Definition at line 91 of file MultiStateWidget.cpp.

References m_current_index, and m_pixmaps.

92 {
93  QPainter p(this);
94  p.drawPixmap(0, 0, m_pixmaps[m_current_index]);
95 }
QVector< QPixmap > m_pixmaps

◆ setID()

void Kwave::MultiStateWidget::setID ( int  id)

Sets the number that will passed as argument to the "clicked" signal.

Parameters
idnew identifier

Definition at line 45 of file MultiStateWidget.cpp.

References m_identifier.

46 {
47  m_identifier = id;
48 }

◆ setState

void Kwave::MultiStateWidget::setState ( int  newstate)
slot

Activates a new state, with wrap-around on overflows, limited to [ 0 ... m_pixmaps.count()-1 ].

Parameters
newstateindex of the new state [0...N]

Definition at line 63 of file MultiStateWidget.cpp.

References m_current_index, and m_pixmaps.

Referenced by nextState(), and switchState().

64 {
65  m_current_index = (state % m_pixmaps.count());
66  repaint();
67 }
QVector< QPixmap > m_pixmaps
Here is the caller graph for this function:

◆ switchState

void Kwave::MultiStateWidget::switchState ( bool  on)
slot

For widgets that have only two states (on and off), this selects state 1 or 0

Parameters
onif true, switch on (state 1), otherwise switch off (state 0)

Definition at line 70 of file MultiStateWidget.cpp.

References setState().

Referenced by Kwave::TrackView::TrackView().

71 {
72  setState((on) ? 1 : 0);
73 }
void setState(int newstate)
Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ m_current_index

int Kwave::MultiStateWidget::m_current_index
private

index of the current state

Definition at line 111 of file MultiStateWidget.h.

Referenced by nextState(), paintEvent(), and setState().

◆ m_identifier

int Kwave::MultiStateWidget::m_identifier
private

identifier used for the clicked() signal

Definition at line 114 of file MultiStateWidget.h.

Referenced by nextState(), and setID().

◆ m_pixmaps

QVector<QPixmap> Kwave::MultiStateWidget::m_pixmaps
private

list of QPixmaps

Definition at line 117 of file MultiStateWidget.h.

Referenced by addPixmap(), paintEvent(), setState(), and ~MultiStateWidget().


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