AlbumShaper 1.0a3
DynamicSlider Class Reference

A more dynamic slider that provides moving tooltips that show the slider value. More...

#include <dynamicSlider.h>

Inheritance diagram for DynamicSlider:
Collaboration diagram for DynamicSlider:

Signals

void mouseHasMoved ()
 

Public Member Functions

 DynamicSlider (Qt::Orientation orientation, QWidget *parent, const char *name=0)
 
 ~DynamicSlider ()
 
void setZeroString (QString val)
 when set, a zero string is shown instead of the current value/prefix/suffix when the slider value is 0
 
void setPrefix (QString val)
 set the prefix that is displayed before the current slider value
 
void setPrefixes (QString prefix1, QString prefix2)
 set two prefix values, one for when the value is positive and one for when the value is negative.
 
void setSuffix (QString val)
 set the suffix that is displayed after the current slider value
 
void setSuffixes (QString suffix1, QString suffix2)
 set two suffix values, one for when the value is positive and one for when the value is negative.
 
QPoint getMousePos ()
 

Protected Member Functions

void mouseMoveEvent (QMouseEvent *e)
 
virtual QString mapValToString ()
 subclass DynamicSlider and reimplement this method to change the behavior used to display slider values
 

Private Slots

void updateTooltipLabel ()
 

Private Attributes

QString zeroString
 
QString prefix1
 
QString prefix2
 
QString suffix1
 
QString suffix2
 
SliderToolTiptooltip
 
QPoint cachedMousePos
 

Detailed Description

A more dynamic slider that provides moving tooltips that show the slider value.

Definition at line 23 of file dynamicSlider.h.

Constructor & Destructor Documentation

◆ DynamicSlider()

DynamicSlider::DynamicSlider ( Qt::Orientation orientation,
QWidget * parent,
const char * name = 0 )

Definition at line 23 of file dynamicSlider.cpp.

24 : QSlider(orientation, parent, name)
25{
26 //determine the parent screen the tooltip will be displayed in and create tooltip
27 int scr = QApplication::desktop()->screenNumber( this );
28 tooltip = new SliderToolTip( QApplication::desktop()->screen( scr ), this);
30
31 //make sure tooltip label is updated when the slider value changes
32 connect( this, SIGNAL( valueChanged(int) ),
33 this, SLOT( updateTooltipLabel() ) );
34}
SliderToolTip * tooltip
void updateTooltipLabel()
private class used by the DynamicSlider to show tooltips. do not use!

References tooltip, and updateTooltipLabel().

◆ ~DynamicSlider()

DynamicSlider::~DynamicSlider ( )

Definition at line 36 of file dynamicSlider.cpp.

37{
38 delete tooltip;
39 tooltip = NULL;
40}

References tooltip.

Member Function Documentation

◆ getMousePos()

QPoint DynamicSlider::getMousePos ( )

Definition at line 125 of file dynamicSlider.cpp.

125{ return cachedMousePos; }
QPoint cachedMousePos

References cachedMousePos.

Referenced by SliderToolTip::update().

◆ mapValToString()

QString DynamicSlider::mapValToString ( )
protectedvirtual

subclass DynamicSlider and reimplement this method to change the behavior used to display slider values

Reimplemented in BlurSharpenSlider.

Definition at line 76 of file dynamicSlider.cpp.

77{
78 //the default behavior is to simply use the slider value directly
79 if( orientation() == Qt::Vertical )
80 return QString("%1").arg( -value() );
81 else
82 return QString("%1").arg(value());
83}

Referenced by updateTooltipLabel().

◆ mouseHasMoved

void DynamicSlider::mouseHasMoved ( )
signal

Referenced by mouseMoveEvent().

◆ mouseMoveEvent()

void DynamicSlider::mouseMoveEvent ( QMouseEvent * e)
protected

Definition at line 117 of file dynamicSlider.cpp.

118{
119 //cache the mouse position since the tooltip will need this information when updating itself
120 cachedMousePos = e->pos();
121 QSlider::mouseMoveEvent(e);
122 emit mouseHasMoved();
123}
void mouseHasMoved()

References cachedMousePos, and mouseHasMoved().

◆ setPrefix()

void DynamicSlider::setPrefix ( QString val)

set the prefix that is displayed before the current slider value

Definition at line 48 of file dynamicSlider.cpp.

49{
50 prefix1 = val;
51 prefix2 = QString::null;
53}

References prefix1, prefix2, and updateTooltipLabel().

◆ setPrefixes()

void DynamicSlider::setPrefixes ( QString prefix1,
QString prefix2 )

set two prefix values, one for when the value is positive and one for when the value is negative.

Definition at line 55 of file dynamicSlider.cpp.

56{
57 prefix1 = v1;
58 prefix2 = v2;
60}

References prefix1, prefix2, and updateTooltipLabel().

Referenced by BlurSharpenSlider::BlurSharpenSlider(), and HistogramEditor::HistogramEditor().

◆ setSuffix()

void DynamicSlider::setSuffix ( QString val)

set the suffix that is displayed after the current slider value

Definition at line 62 of file dynamicSlider.cpp.

63{
64 suffix1 = val;
65 suffix2 = QString::null;
67}

References suffix1, suffix2, and updateTooltipLabel().

Referenced by BlurSharpenSlider::BlurSharpenSlider().

◆ setSuffixes()

void DynamicSlider::setSuffixes ( QString suffix1,
QString suffix2 )

set two suffix values, one for when the value is positive and one for when the value is negative.

Definition at line 69 of file dynamicSlider.cpp.

70{
71 suffix1 = v1;
72 suffix2 = v2;
74}

References suffix1, suffix2, and updateTooltipLabel().

◆ setZeroString()

void DynamicSlider::setZeroString ( QString val)

when set, a zero string is shown instead of the current value/prefix/suffix when the slider value is 0

Definition at line 42 of file dynamicSlider.cpp.

43{
44 zeroString = val;
46}
QString zeroString

References updateTooltipLabel(), and zeroString.

Referenced by BlurSharpenSlider::BlurSharpenSlider(), and HistogramEditor::HistogramEditor().

◆ updateTooltipLabel

void DynamicSlider::updateTooltipLabel ( )
privateslot

Definition at line 85 of file dynamicSlider.cpp.

86{
87 //determine string that will be used for tooltip
88 QString tipString;
89
90 //if the value is zero and a zero string has been provided used that
91 if( value() == 0 && !zeroString.isNull() )
92 {
93 tipString = zeroString;
94 }
95 //otherwise construct a tip string using provided prefixes, suffixes, and the current slider value
96 else
97 {
98 //determine prefix and suffix that will be used to construct tooltip string
99 QString p, s;
100 if( value() > 0 || prefix2.isNull() ) p = prefix1;
101 else p = prefix2;
102
103 if( value() > 0 || suffix2.isNull() ) s = suffix1;
104 else s = suffix2;
105
106 //construct tipstring
107 tipString = QString("%1%2%3").arg(p).arg(mapValToString()).arg(s);
108
109 }
110
111 //update tooltip
112 tooltip->setText( tipString );
113 tooltip->adjustSize();
114 if( tooltip->isShown() ) qApp->processEvents();
115}
virtual QString mapValToString()
subclass DynamicSlider and reimplement this method to change the behavior used to display slider valu...

References mapValToString(), prefix1, prefix2, suffix1, suffix2, tooltip, and zeroString.

Referenced by DynamicSlider(), setPrefix(), setPrefixes(), setSuffix(), setSuffixes(), and setZeroString().

Member Data Documentation

◆ cachedMousePos

QPoint DynamicSlider::cachedMousePos
private

Definition at line 63 of file dynamicSlider.h.

Referenced by getMousePos(), and mouseMoveEvent().

◆ prefix1

QString DynamicSlider::prefix1
private

Definition at line 59 of file dynamicSlider.h.

Referenced by setPrefix(), setPrefixes(), and updateTooltipLabel().

◆ prefix2

QString DynamicSlider::prefix2
private

Definition at line 59 of file dynamicSlider.h.

Referenced by setPrefix(), setPrefixes(), and updateTooltipLabel().

◆ suffix1

QString DynamicSlider::suffix1
private

Definition at line 60 of file dynamicSlider.h.

Referenced by setSuffix(), setSuffixes(), and updateTooltipLabel().

◆ suffix2

QString DynamicSlider::suffix2
private

Definition at line 60 of file dynamicSlider.h.

Referenced by setSuffix(), setSuffixes(), and updateTooltipLabel().

◆ tooltip

SliderToolTip* DynamicSlider::tooltip
private

Definition at line 62 of file dynamicSlider.h.

Referenced by DynamicSlider(), updateTooltipLabel(), and ~DynamicSlider().

◆ zeroString

QString DynamicSlider::zeroString
private

Definition at line 57 of file dynamicSlider.h.

Referenced by setZeroString(), and updateTooltipLabel().


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