• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • widgets
timeunitbox.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  timeunitbox.cpp - description
3  -------------------
4  begin : Sat Apr 27 2002
5  copyright : (C) 2002 by Jason Harris
6  email : kstars@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "timeunitbox.h"
19 #include "timeunitbox.moc"
20 
21 #include <cstdlib>
22 
23 #include <QPushButton>
24 #include <QVBoxLayout>
25 
26 #include <kdebug.h>
27 
28 static const char * const up_arrow[] = {
29 "22 11 4 1",
30 " c None",
31 ". c #000000",
32 "+ c #808080",
33 "@ c #BFBFBF",
34 " ",
35 " ",
36 " .. ",
37 " .++. ",
38 " .+ @. ",
39 " .+ @. ",
40 " .+ @. ",
41 " .+ @. ",
42 " .+ @. ",
43 " + @ ",
44 " "};
45 
46 static const char * const down_arrow[] = {
47 "22 11 4 1",
48 " c None",
49 ". c #808080",
50 "+ c #BFBFBF",
51 "@ c #000000",
52 " ",
53 " . + ",
54 " @. +@ ",
55 " @. +@ ",
56 " @. +@ ",
57 " @. +@ ",
58 " @. +@ ",
59 " @..@ ",
60 " @@ ",
61 " ",
62 " "};
63 
64 TimeUnitBox::TimeUnitBox(QWidget *parent, bool daysonly )
65  : QWidget( parent ) {
66 
67  QVBoxLayout *vlay = new QVBoxLayout(this);
68  vlay->setMargin(0);
69  vlay->setSpacing(0);
70 
71  UpButton = new QPushButton( QPixmap(up_arrow), "", this );
72  UpButton->setMaximumWidth( 26 );
73  UpButton->setMaximumHeight( 13 );
74  DownButton = new QPushButton( QPixmap(down_arrow), "", this );
75  DownButton->setMaximumWidth( 26 );
76  DownButton->setMaximumHeight( 13 );
77 
78  vlay->addWidget( UpButton );
79  vlay->addWidget( DownButton );
80  // setLayout( vlay );
81 
82  setDaysOnly( daysonly );
83 
84  connect( UpButton, SIGNAL( clicked() ), this, SLOT( increase() ) );
85  connect( DownButton, SIGNAL( clicked() ), this, SLOT( decrease() ) );
86 }
87 
88 TimeUnitBox::~TimeUnitBox(){
89 }
90 
91 void TimeUnitBox::setDaysOnly( bool daysonly ) {
92  if ( daysonly ) {
93  setMinimum( 1-DAYUNITS );
94  setMaximum( DAYUNITS-1 );
95  setValue( 1 ); // Start out with days units
96 
97  UnitStep[0] = 0;
98  UnitStep[1] = 1;
99  UnitStep[2] = 5;
100  UnitStep[3] = 8;
101  UnitStep[4] = 14;
102  } else {
103  setMinimum( 1-ALLUNITS );
104  setMaximum( ALLUNITS-1 );
105  setValue( 1 ); // Start out with seconds units
106 
107  UnitStep[0] = 0;
108  UnitStep[1] = 4;
109  UnitStep[2] = 10;
110  UnitStep[3] = 16;
111  UnitStep[4] = 21;
112  UnitStep[5] = 25;
113  UnitStep[6] = 28;
114  UnitStep[7] = 34;
115  }
116 }
117 
118 void TimeUnitBox::increase() {
119  if ( value() < maxValue() ) {
120  setValue( value()+1 );
121  emit valueChanged( value() );
122  }
123 }
124 
125 void TimeUnitBox::decrease() {
126  if ( value() > minValue() ) {
127  setValue( value()-1 );
128  emit valueChanged( value() );
129  }
130 }
131 
132 int TimeUnitBox::unitValue() {
133  int uval;
134  if ( value() >= 0 ) uval = UnitStep[ value() ];
135  else uval = -1*UnitStep[ abs( value() ) ];
136  return uval;
137 }
138 
139 int TimeUnitBox::getUnitValue( int val ) {
140  if ( val >= 0 ) return UnitStep[ val ];
141  else return -1*UnitStep[ abs( val ) ];
142 }
TimeUnitBox::maxValue
int maxValue() const
Definition: timeunitbox.h:80
TimeUnitBox::value
int value() const
Definition: timeunitbox.h:66
up_arrow
static const char *const up_arrow[]
Definition: timeunitbox.cpp:28
QWidget
TimeUnitBox::getUnitValue
int getUnitValue(int)
the same as unitValue, except you can get the UnitStep for any value, not just the current one...
Definition: timeunitbox.cpp:139
TimeUnitBox::valueChanged
void valueChanged(int)
timeunitbox.h
TimeUnitBox::unitValue
int unitValue()
Definition: timeunitbox.cpp:132
TimeUnitBox::setMinimum
void setMinimum(int minValue)
Set the minimum value for the internal time-unit value.
Definition: timeunitbox.h:70
ALLUNITS
#define ALLUNITS
Definition: timeunitbox.h:23
TimeUnitBox::setValue
void setValue(int value)
Set the value which describes which time-unit is displayed in the TimeSpinBox.
Definition: timeunitbox.h:63
TimeUnitBox::setDaysOnly
void setDaysOnly(bool daysonly)
Definition: timeunitbox.cpp:91
TimeUnitBox::setMaximum
void setMaximum(int maxValue)
Set the maximum value for the internal time-unit value.
Definition: timeunitbox.h:73
TimeUnitBox::~TimeUnitBox
~TimeUnitBox()
Destructor (empty)
Definition: timeunitbox.cpp:88
TimeUnitBox::TimeUnitBox
TimeUnitBox(QWidget *parent=0, bool daysonly=false)
Constructor.
Definition: timeunitbox.cpp:64
down_arrow
static const char *const down_arrow[]
Definition: timeunitbox.cpp:46
DAYUNITS
#define DAYUNITS
Definition: timeunitbox.h:24
TimeUnitBox::minValue
int minValue() const
Definition: timeunitbox.h:77
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal