tpscfg.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Stephan Broennimann (vb)
00008 
00009   RCS information
00010    $Name: OSB_060808 $
00011    $Revision: 1.30 $
00012 
00013   License
00014    OSB rating and billing library for communication networks
00015    Copyright (C) 2004, 2005, 2006  OSB systems
00016 
00017    This file may be distributed and/or modify under the terms of the
00018    GNU General Public License (GPL) as published by the Free Software
00019    Foundation which is provided in the file LICENSE.GPL included in the
00020    packaging of this file.
00021 
00022    The file is distributed in the hope that it will be useful, but WITHOUT
00023    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00024    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00025    for more details.
00026 
00027    Holders of a OSB Commercial License may use this file under the terms
00028    and conditions of this commercial license.
00029  */
00030 #ifndef _TPSCFG_H_
00031 #define _TPSCFG_H_
00032 
00033 // ************************************************************************
00034 // included header files
00035 // + standard includes
00036 
00037 // + libraries
00038 #include <osbid.h>
00039 #include <chrono.h>
00040 #include <qgroupbox.h>
00041 #include <qlabel.h>
00042 #include <qpopupmenu.h>
00043 
00044 // + local headers
00045 #include "osbframes.h"
00046 
00047 // ************************************************************************
00048 // class declarations
00049 namespace OSB_LIB {
00050     class Time;
00051     class TariffPeriod;
00052     class DayClass;
00053     class TpsConfig;
00054 }
00055 namespace OSB_GUI {
00056     class LeFixedWidth;                 // osblineedits.h
00057     class TpColor;                      // tputils.h
00058 }
00059 // + Qt
00060 class QLabel;
00061 class QHBoxLayout;
00062 class QPushButton;
00063 class QLineEdit;
00064 class QTimeEdit;
00065 
00066 // ************************************************************************
00067 // namespace extensions
00068 namespace OSB_GUI {
00069 
00070 // ************************************************************************
00071 // forward declarations
00072     class TpInfoToggle;
00073     class DcInfoToggle;
00074     class DcInfo;
00075     class DcInfoTicks;
00076     class SwitchTimeEvent;
00077 
00083     const int tpsHourSize = 24;
00084 
00085 // ************************************************************************
00086 // class definitions
00087 
00094     class TpInfoGroup : public QGroupBox {
00095         Q_OBJECT                        // for vim ->;
00096     private:
00098         typedef OSB_LIB::Id<OSB_LIB::TariffPeriod> TpId;
00100         typedef std::list<TpInfoToggle*> Infos;
00102         static const int numCols_ = 2;
00103     public:
00105         explicit TpInfoGroup(
00106                   QWidget* parent,
00107             const char*    name = "tpGroup_"
00108         );
00109     public:
00111         void languageChange();
00118         OSB_LIB::Id<OSB_LIB::TariffPeriod> tpId() const;
00127         bool addTp(
00128             const OSB_LIB::TariffPeriod& tp
00129         );
00131         bool clicksOn() const;
00133         void setClicks(bool on);
00141         void setTp(
00142             const OSB_LIB::Id<OSB_LIB::TariffPeriod>& tpId,
00143                   bool                                on
00144         );
00146         bool exists(
00147             const OSB_LIB::Id<OSB_LIB::TariffPeriod>& tpId
00148         ) const;
00149     signals:
00156         void sigSelected(const TpId& tpId);
00157     private:
00164         void buildLayout();
00172         TpInfoToggle* find(
00173             const OSB_LIB::Id<OSB_LIB::TariffPeriod>& tpId
00174         );
00175     private slots:
00181         void infoClicked(TpInfoToggle& info);
00182     private:
00188         TpId curTp_;
00190         Infos infos_;
00192         bool clicksOn_;
00194         QSpacerItem* spacer_;
00196         QLabel* lbNone_;
00198         QGridLayout* layout_;
00199     };                                  // class TpInfoGroup
00200 
00208     class DcInfoGroup : public QGroupBox {
00209         Q_OBJECT                        // for vim ->;
00210     private:
00212         typedef std::pair<DcInfoToggle*, DcInfo*> Info;
00214         typedef std::list<Info> Infos;
00216         typedef OSB_LIB::Id<OSB_LIB::DayClass> DcId;
00218         enum {
00219             colLabels = 0,
00220             colEmpty  = 1,
00221             colTicks  = 2, colSpacer = colTicks,
00222             colHours  = 3
00223         };
00224     public:
00226         explicit DcInfoGroup(
00227                   QWidget* parent,
00228             const char*    name = "dcGroup_"
00229         );
00230     public:
00232         void languageChange();
00239         OSB_LIB::Id<OSB_LIB::DayClass> dcId() const;
00241         void getConfig(OSB_LIB::TpsConfig* config) const;
00243         bool clicksOn() const;
00245         void setClicks(bool on);
00253         void addSwitchTime(
00254             const OSB_LIB::DayClass&     dc,
00255             const OSB_LIB::TariffPeriod& tp,
00256             const OSB_LIB::Time&         stime
00257         );
00267         void delSwitchTime(
00268             const OSB_LIB::Time&                  stime,
00269             const OSB_LIB::Id<OSB_LIB::DayClass>& dcId
00270         );
00277         void setDc(
00278             const OSB_LIB::Id<OSB_LIB::DayClass>& dcId,
00279                   bool                            on
00280         );
00282         bool exists(
00283             const OSB_LIB::Id<OSB_LIB::DayClass>& dcId
00284         ) const;
00293         Info* addDc(
00294             const OSB_LIB::DayClass& dc
00295         );
00296     signals:
00304         void sigSwitchTime(const SwitchTimeEvent& event);
00311         void sigSelected(const DcId& dcId);
00312     private:
00319         void buildLayout();
00327         Info* find(const DcId& dcId);
00338         void initInfo(
00339             Info* info,
00340             bool  sigLabel = true,
00341             bool  sigHours = true
00342         );
00343     private slots:
00351         void labelClicked(const DcId& dcId);
00359         void switchTimeEvent(const SwitchTimeEvent& event);
00360     private:
00362         Infos infos_;
00364         Info noInfo_;
00370         DcId curDc_;
00372         QFrame* background_;
00374         bool clicksOn_;
00376         QSpacerItem* spacer_;
00378         DcInfoTicks* ticks_;
00380         QGridLayout* layout_;
00381     };                                  // class DcInfoGroup
00382 
00386     class TpInfoToggle : public ToggleFrame {
00387         Q_OBJECT                            // for vim ->;
00388     public:
00390         explicit TpInfoToggle(
00391             const OSB_LIB::TariffPeriod& tp,
00392                   QWidget* parent,
00393             const char*    name = "tpInfo_",
00394                   WFlags   flags = 0
00395         );
00396     public:
00398         OSB_LIB::Id<OSB_LIB::TariffPeriod> tpId() const;
00400         std::string text() const;
00407         void setLineWidth(int lw);
00409         void setName(const std::string& name);
00410     private:
00416         void leftClicked();
00417     signals:
00423         void leftClicked(TpInfoToggle& tpInfo);
00424     private:
00426         OSB_LIB::Id<OSB_LIB::TariffPeriod> tpId_;
00428         QLabel* label_;
00430         TpColor* color_;
00432         QHBoxLayout* layout_;
00433     };                                      // class TpInfoToggle
00434 
00438     class DcInfoToggle : public QLabel {
00439         Q_OBJECT                        // for vim ->;
00440     public:
00442         typedef OSB_LIB::Id<OSB_LIB::DayClass> DcId;
00443     public:
00445         DcInfoToggle(
00446             const OSB_LIB::DayClass& dc,
00447                   QWidget*           parent,
00448             const char*              name = "dcLabel_"
00449         );
00451         explicit DcInfoToggle(
00452                   QWidget*     parent,
00453             const char*        name = "dcLabel_"
00454         );
00455     public:
00457         OSB_LIB::Id<OSB_LIB::DayClass> dcId() const;
00459         bool isOn() const;
00461         void setOn(bool on);
00462     signals:
00468         void leftClicked(const DcId& dcId);
00469     private:
00475         void mousePressEvent(QMouseEvent *e);
00483         QSize minimumSizeHint() const;
00485         QSize sizeHint() const;
00486     private:
00488         DcId dcId_;
00490         bool on_;
00491     };                                  // class DcInfoToggle
00492 
00496     class DcInfo : public QWidget {
00497         Q_OBJECT                        // for vim ->;
00498     private:
00500         typedef OSB_LIB::Id<OSB_LIB::DayClass> DcId;
00502         typedef OSB_LIB::Id<OSB_LIB::TariffPeriod> TpId;
00508         typedef std::pair<TpId, QColor> StInfo;
00518         typedef std::map<OSB_LIB::Time, StInfo> SwitchTimes;
00519     public:
00521         explicit DcInfo(
00522             const DcId&    dcId,
00523                   QWidget* parent,
00524             const char*    name = "dcInfo_",
00525                   WFlags   fl = 0
00526         );
00528         const DcId& dcId() const;
00530         void getConfig(OSB_LIB::TpsConfig* config) const;
00537         void add(
00538             const OSB_LIB::TariffPeriod& tp,
00539             const OSB_LIB::Time&         stime
00540         );
00546         void remove(const OSB_LIB::Time& stime);
00547     signals:
00556         void sigSwitchTime(
00557             const SwitchTimeEvent& event
00558         );
00559     private:
00565         void setEvent(
00566             SwitchTimeEvent* event
00567         );
00573         void mouseMoveEvent(QMouseEvent* e);
00579         void mousePressEvent(QMouseEvent* e);
00586         void mouseEvent(QMouseEvent* e);
00590         void paintEvent(QPaintEvent*);
00598         void showHours (
00599                   QPainter&      painter,
00600             const OSB_LIB::Time& start,
00601             const OSB_LIB::Time& end
00602         );
00609         OSB_LIB::Time x2time(int x);
00618         int time2x(
00619             const OSB_LIB::Time& time,
00620                   bool           isEnd = false
00621         );
00622     private:
00624         DcId dcId_;
00626         SwitchTimes sTimes_;
00627     };                                  // class DcInfo
00628 
00632     class DcInfoTicks : public QWidget {
00633     public:
00635         explicit DcInfoTicks(
00636                   QWidget* parent,
00637             const char*    name   = "ticks_",
00638                   WFlags   fl     = 0
00639         );
00640     public:
00642         int xZero() const { return xZero_; }
00643     private:
00645         void paintEvent(QPaintEvent*);
00646     private:
00648         int xZero_;
00649     };
00650 
00654     class SwitchTimeInfo : public QGroupBox
00655     {
00656         Q_OBJECT                        // for vim ->;
00657     public:
00659         explicit SwitchTimeInfo(
00660                   QWidget* parent,
00661             const char*    name = "gbSt_"
00662         );
00664         void languageChange();
00670         void setup(bool showOnly);
00672         OSB_LIB::Time switchTime() const;
00674         OSB_LIB::Time newTime() const;
00682         void switchTimeEvent(const SwitchTimeEvent& event);
00683     private:
00685         QLabel*       tlSwitchTime_;
00687         LeFixedWidth* switchTime_;
00689         QLabel*       tlNewTime_;
00697         QTimeEdit*    newTime_;
00699         QLabel*       tlEnd_;
00701         LeFixedWidth* endTime_;
00703         QGridLayout*  layout_;
00704     };                                  // class SwitchTimeInfo
00705 
00709     struct SwitchTimeEvent {
00711         typedef OSB_LIB::Id<OSB_LIB::DayClass> DcId;
00713         typedef OSB_LIB::Id<OSB_LIB::TariffPeriod> TpId;
00714     public:
00720         SwitchTimeEvent(
00721             const DcId&         dcId,
00722             const OSB_LIB::Time selected
00723         );
00724     public:
00726         DcId dcId_;
00733         TpId tpId_;
00740         OSB_LIB::Time switchTime_;
00742         OSB_LIB::Time selected_;
00749         OSB_LIB::Time next_;
00750     };
00751 
00755     class TpMenu : public QPopupMenu {
00756         Q_OBJECT                        // for vim ->;
00757     public:
00758         // Short-hand for a tariff period object id.
00759         typedef OSB_LIB::Id<OSB_LIB::TariffPeriod> TpId;
00760     public:
00762         explicit TpMenu(
00763                   QWidget* parent,
00764             const char*    name    = "tpMenu_"
00765         );
00766     public:
00773         void addTp(
00774             const OSB_LIB::TariffPeriod& tp,
00775                   bool                   enabled
00776         );
00783         void checkTp(
00784             const TpId& tpId,
00785                   bool  check
00786         );
00787     signals:
00793         void activated(TpId tpId);
00794     private slots:
00798         void activationEvent(int id);
00799     };                                  // class TpMenu
00800 
00804     class DcMenu : public QPopupMenu {
00805         Q_OBJECT                        // for vim ->;
00806     public:
00807         // Short-hand for a tariff period object id.
00808         typedef OSB_LIB::Id<OSB_LIB::DayClass> DcId;
00809     public:
00811         explicit DcMenu(
00812                   QWidget* parent,
00813             const char*    name    = "dcMenu_"
00814         );
00815     public:
00822         void addDc(
00823             const OSB_LIB::DayClass& dc,
00824                   bool               enabled
00825         );
00832         void checkDc(
00833             const DcId& dcId,
00834                   bool  check
00835         );
00836     signals:
00842         void activated(DcId dcId);
00843     private slots:
00847         void activationEvent(int id);
00848     };                                  // class DcMenu
00849 
00853     struct SwitchTimeCmd {
00854     public:
00856         enum Cmd {
00858             cmdRemove = 1,
00860             cmdAdd    = 2
00861         };
00862     public:
00864         SwitchTimeCmd(Cmd cmd);
00866         operator Cmd() const;
00868         Cmd cmd_;
00869     };                                  // SwitchTimeCmd
00870 
00874     class StMenu : public QPopupMenu {
00875         Q_OBJECT                        // for vim ->;
00876     public:
00878         explicit StMenu(
00879                   QWidget* parent,
00880             const char*    name    = "stMenu_"
00881         );
00882     public:
00884         void languageChange();
00886         void enableCmd(
00887             SwitchTimeCmd::Cmd cmd,
00888             bool               enabled
00889         );
00890     signals:
00896         void activated(
00897             const SwitchTimeCmd& cmd
00898         );
00899     private slots:
00903         void activationEvent(int id);
00904     };                                  // class StMenu
00905 }                                       // namespace OSB_GUI
00906 
00907 // ************************************************************************
00908 // inline definitions
00909 namespace OSB_GUI {
00910 }                                       // namespace OSB_GUI
00911 #endif                                  // #ifndef _TPSCFG_H_

Generated on Sat Sep 2 14:17:37 2006 for OSB Library by  doxygen 1.4.7