1 /* 2 KSysGuard, the KDE System Guard 3 4 Copyright (c) 1999 - 2002 Chris Schlaeger <cs@kde.org> 5 6 This program is free software; you can redistribute it and/or 7 modify it under the terms of the GNU General Public License as 8 published by the Free Software Foundation; either version 2 of 9 the License or (at your option) version 3 or any later version 10 accepted by the membership of KDE e.V. (or its successor approved 11 by the membership of KDE e.V.), which shall act as a proxy 12 defined in Section 14 of version 3 of the license. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef KSG_WORKSHEET_H 24 #define KSG_WORKSHEET_H 25 26 #include <QWidget> 27 #include <QTimer> 28 29 #include <SensorDisplay.h> 30 #include "SharedSettings.h" 31 32 class QDomElement; 33 class QDragEnterEvent; 34 class QDropEvent; 35 class QGridLayout; 36 class QString; 37 class QStringList; 38 39 /** 40 A WorkSheet contains the displays to visualize the sensor results. When 41 creating the WorkSheet you must specify the number of columns. Displays 42 can be added and removed on the fly. The grid layout will handle the 43 layout. The number of columns can not be changed. Displays are added by 44 dragging a sensor from the sensor browser over the WorkSheet. 45 */ 46 class WorkSheet : public QWidget 47 { 48 Q_OBJECT 49 50 public: 51 explicit WorkSheet( QWidget* parent); 52 WorkSheet( int rows, int columns, float interval, QWidget* parent); 53 ~WorkSheet() override; 54 55 bool load( const QString &fileName ); 56 bool save( const QString &fileName ); 57 bool exportWorkSheet( const QString &fileName ); 58 59 void cut(); 60 void copy(); 61 void paste(); 62 63 void setFileName( const QString &fileName ); 64 QString fileName() const; 65 66 QString fullFileName() const; 67 isLocked()68 bool isLocked() const {return mSharedSettings.locked;} 69 70 QString title() const; 71 QString translatedTitle() const; 72 void refreshSheet(); 73 74 KSGRD::SensorDisplay* addDisplay( const QString &hostname, 75 const QString &monitor, 76 const QString &sensorType, 77 const QString &sensorDescr, 78 int row, int column ); 79 80 void settings(); 81 float updateInterval() const; 82 83 public Q_SLOTS: 84 void showPopupMenu( KSGRD::SensorDisplay *display ); 85 void setTitle( const QString &title ); 86 void applyStyle(); 87 88 Q_SIGNALS: 89 void titleChanged( QWidget *sheet ); 90 91 protected: 92 93 void changeEvent( QEvent * event ) override; 94 QSize sizeHint() const override; 95 void dragMoveEvent( QDragMoveEvent* ) override; 96 void dragEnterEvent( QDragEnterEvent* ) override; 97 void dropEvent( QDropEvent* ) override; 98 bool event( QEvent* ) override; 99 void setUpdateInterval( float interval); 100 101 private: 102 void removeDisplay( KSGRD::SensorDisplay *display ); 103 104 bool replaceDisplay( int row, int column, QDomElement& element, int rowSpan = 1, int columnSpan = 1 ); 105 106 void replaceDisplay( int row, int column, KSGRD::SensorDisplay* display = nullptr, int rowSpan = 1, int columnSpan = 1 ); 107 108 void collectHosts( QStringList &list ); 109 110 void createGrid( int rows, int columns ); 111 112 void resizeGrid( int rows, int columns ); 113 114 KSGRD::SensorDisplay* currentDisplay( int *row = nullptr, int *column = nullptr ); 115 116 void fixTabOrder(); 117 118 QString currentDisplayAsXML(); 119 120 int mRows; 121 int mColumns; 122 123 QGridLayout* mGridLayout; 124 QString mFileName; 125 QString mFullFileName; 126 QString mTitle; 127 QString mTranslatedTitle; 128 129 SharedSettings mSharedSettings; 130 131 QTimer mTimer; 132 133 enum DisplayType { DisplayDummy, DisplayFancyPlotter, DisplayMultiMeter, DisplayDancingBars, DisplaySensorLogger, DisplayListView, DisplayLogFile, DisplayProcessControllerRemote, DisplayProcessControllerLocal }; 134 135 KSGRD::SensorDisplay* insertDisplay( DisplayType displayType, QString displayTitle, int row, int column, int rowSpan = 1, int columnSpan = 1); 136 }; 137 138 #endif 139