Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef KLFGUIUTIL_H
00025 #define KLFGUIUTIL_H
00026
00027
00028 #include <QString>
00029 #include <QByteArray>
00030 #include <QComboBox>
00031 #include <QWidget>
00032 #include <QDialog>
00033 #include <QProgressDialog>
00034 #include <QMouseEvent>
00035 #include <QPaintEvent>
00036 #include <QTime>
00037 #include <QGridLayout>
00038 #include <QDoubleSpinBox>
00039 #include <QLabel>
00040 #include <QMovie>
00041 #include <QPainter>
00042
00043 #include <klfutil.h>
00044
00045
00047
00063 class KLF_EXPORT KLFProgressReporter : public QObject
00064 {
00065 Q_OBJECT
00066 public:
00067 KLFProgressReporter(int min, int max, QObject *parent = NULL);
00069 virtual ~KLFProgressReporter();
00070
00071 inline int min() const { return pMin; }
00072 inline int max() const { return pMax; }
00073
00074 signals:
00084 void progress(int progressValue);
00085
00090 void finished();
00091
00092 public slots:
00099 void doReportProgress(int value);
00100
00101 private:
00102 int pMin;
00103 int pMax;
00104 bool pFinished;
00105 };
00106
00172 class KLF_EXPORT KLFProgressDialog : public QProgressDialog
00173 {
00174 Q_OBJECT
00175 public:
00177 KLFProgressDialog(QString labelText = QString(), QWidget *parent = NULL);
00178
00181 KLFProgressDialog(bool canCancel, QString labelText, QWidget *parent);
00182
00183 virtual ~KLFProgressDialog();
00184
00185
00186 public slots:
00187
00190 virtual void setDescriptiveText(const QString& labelText);
00194 virtual void startReportingProgress(KLFProgressReporter *progressReporter,
00195 const QString& descriptiveText);
00199 virtual void startReportingProgress(KLFProgressReporter *progressReporter);
00200
00202 virtual void setValue(int value);
00203
00204 protected:
00205 void paintEvent(QPaintEvent *event);
00206
00207 private:
00208 void setup(bool canCancel);
00209 void init(const QString& labelText);
00210
00211 KLFProgressReporter *pProgressReporter;
00212
00213 bool pGotPaintEvent;
00214 };
00215
00216
00237 class KLF_EXPORT KLFPleaseWaitPopup : public QLabel
00238 {
00239 Q_OBJECT
00240 Q_PROPERTY(bool disableUi READ willDisableUi WRITE setDisableUi) ;
00241 public:
00260 KLFPleaseWaitPopup(const QString& text, QWidget *callingWidget = NULL, bool alwaysAbove = false);
00261 virtual ~KLFPleaseWaitPopup();
00262
00263 inline bool willDisableUi() const { return pDisableUi; }
00264
00269 virtual void setDisableUi(bool disableUi);
00270
00272 virtual bool pleaseWaitShown() const { return pGotPaintEvent; }
00273
00276 virtual bool wasUserDiscarded() const { return pDiscarded; }
00277
00278 public slots:
00280 virtual void showPleaseWait();
00281
00282 protected:
00283 virtual void mousePressEvent(QMouseEvent *event);
00284 virtual void paintEvent(QPaintEvent *event);
00285
00286 private:
00287 QWidget *pParentWidget;
00288 bool pDisableUi;
00289 bool pGotPaintEvent;
00290 bool pDiscarded;
00291 };
00292
00293
00305 class KLF_EXPORT KLFDelayedPleaseWaitPopup : public KLFPleaseWaitPopup
00306 {
00307 Q_OBJECT
00308 public:
00309 KLFDelayedPleaseWaitPopup(const QString& text, QWidget *callingWidget = NULL);
00310 virtual ~KLFDelayedPleaseWaitPopup();
00311
00312 virtual void setDelay(int ms);
00313
00314 public slots:
00315 virtual void process();
00316
00317 private:
00318 int pDelay;
00319 QTime timer;
00320 };
00321
00322
00339 class KLF_EXPORT KLFEnumComboBox : public QComboBox
00340 {
00341 Q_OBJECT
00342
00343 Q_PROPERTY(int selectedValue READ selectedValue WRITE setSelectedValue)
00344 public:
00345 KLFEnumComboBox(QWidget *parent = 0);
00346 KLFEnumComboBox(const QList<int>& enumValues, const QStringList& enumTitles,
00347 QWidget *parent = 0);
00348 virtual ~KLFEnumComboBox();
00349
00350 int selectedValue() const;
00351
00352 QString enumText(int enumValue) const;
00353
00354 signals:
00355 void selectedValueChanged(int enumValue);
00356
00357 public slots:
00358 void setSelectedValue(int val);
00359
00360 void setEnumValues(const QList<int>& enumValues, const QStringList& enumTitles);
00361
00362 private slots:
00363 void internalCurrentIndexChanged(int index);
00364
00365 private:
00366 QList<int> pEnumValueList;
00367 QMap<int,QString> pEnumValues;
00368 QMap<int,int> pEnumCbxIndexes;
00369 };
00370
00371
00372
00373
00374
00381 class KLF_EXPORT KLFGridFlowLayout : public QGridLayout
00382 {
00383 Q_OBJECT
00384 public:
00385 KLFGridFlowLayout(int columns, QWidget *parent);
00386 virtual ~KLFGridFlowLayout() { }
00387
00388 virtual int ncolumns() const { return _ncols; }
00389
00390 virtual void insertGridFlowWidget(QWidget *w, Qt::Alignment align = 0);
00391
00392 void clearAll();
00393
00394 protected:
00395 QList<QWidget*> mGridFlowWidgets;
00396 int _ncols;
00397 int _currow, _curcol;
00398 };
00399
00400
00401
00402
00404
00412 class KLFWaitAnimationOverlay : public QLabel
00413 {
00414 Q_OBJECT
00415 Q_PROPERTY(QString waitMovie READ waitMovieFileName WRITE setWaitMovie) ;
00416 Q_PROPERTY(int widthPercent READ widthPercent WRITE setWidthPercent) ;
00417 Q_PROPERTY(int heightPercent READ heightPercent WRITE setHeightPercent) ;
00418 Q_PROPERTY(int positionXPercent READ positionXPercent WRITE setPositionXPercent) ;
00419 Q_PROPERTY(int positionYPercent READ positionYPercent WRITE setPositionYPercent) ;
00420 Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) ;
00421 public:
00422 KLFWaitAnimationOverlay(QWidget *parent);
00423 virtual ~KLFWaitAnimationOverlay();
00424
00425 inline QString waitMovieFileName() const { return (pAnimMovie!=NULL) ? pAnimMovie->fileName() : QString(); }
00426
00427 inline int widthPercent() const { return pWidthPercent; }
00428 inline int heightPercent() const { return pHeightPercent; }
00429 inline int positionXPercent() const { return pPositionXPercent; }
00430 inline int positionYPercent() const { return pPositionYPercent; }
00431
00432 QColor backgroundColor() const;
00433
00434 public slots:
00444 virtual void setWaitMovie(QMovie *movie);
00447 virtual void setWaitMovie(const QString& file);
00448
00450
00461 void setWidthPercent(int widthpercent) { pWidthPercent = widthpercent; }
00462
00464
00466 void setHeightPercent(int heightpercent) { pHeightPercent = heightpercent; }
00467
00469
00480 void setPositionXPercent(int xpc) { pPositionXPercent = xpc; }
00481
00483
00485 void setPositionYPercent(int ypc) { pPositionYPercent = ypc; }
00486
00488
00493 void setBackgroundColor(const QColor& c);
00494
00496 virtual void startWait();
00497
00499 virtual void stopWait();
00500
00501 protected:
00502 virtual void timerEvent(QTimerEvent *event);
00503
00509 virtual QRect calcAnimationLabelGeometry();
00510
00511 private:
00512 bool pIsWaiting;
00513 QMovie *pAnimMovie;
00514 int pAnimTimerId;
00515
00516 int pWidthPercent;
00517 int pHeightPercent;
00518 int pPositionXPercent;
00519 int pPositionYPercent;
00520 };
00521
00522
00523
00526 class KLF_EXPORT KLFDropDataHandler
00527 {
00528 public:
00529 enum OpenDataError {
00530 OpenDataOk = 0,
00531 OpenDataFailed = 1,
00532 OpenDataCantHandle = 2
00533 };
00534
00535 virtual bool canOpenDropData(const QMimeData * data) = 0;
00537 virtual int openDropData(const QMimeData *data) = 0;
00538 };
00539
00540
00541
00542
00543
00544
00560 KLF_EXPORT void klfDrawGlowedImage(QPainter *painter, const QImage& foreground,
00561 const QColor& glow_color = QColor(128, 255, 128, 8),
00562 int radius = 4, bool also_draw_image = true);
00563
00564
00565
00574 KLF_EXPORT QImage klfImageScaled(const QImage& source, const QSize& newSize);
00575
00576
00577
00580 class KLFWindowGeometryRestorer : public QObject
00581 {
00582 Q_OBJECT
00583 public:
00584 KLFWindowGeometryRestorer(QWidget *window);
00585 virtual ~KLFWindowGeometryRestorer();
00586
00587 virtual bool eventFilter(QObject *obj, QEvent *event);
00588 private:
00589 QWidget *pWindow;
00590 };
00591
00592
00593 KLF_EXPORT void klfHideWindows();
00594 KLF_EXPORT void klfRestoreWindows();
00595
00596
00597
00598 #endif