[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klfguiutil.h
Go to the documentation of this file.
1 /***************************************************************************
2  * file klfguiutil.h
3  * This file is part of the KLatexFormula Project.
4  * Copyright (C) 2011 by Philippe Faist
5  * philippe.faist at bluewin.ch
6  * *
7  * This program is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program; if not, write to the *
19  * Free Software Foundation, Inc., *
20  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  ***************************************************************************/
22 /* $Id: klfguiutil.h 698 2011-08-08 08:28:12Z phfaist $ */
23 
24 #ifndef KLFGUIUTIL_H
25 #define KLFGUIUTIL_H
26 
27 
28 #include <QString>
29 #include <QByteArray>
30 #include <QComboBox>
31 #include <QWidget>
32 #include <QDialog>
33 #include <QProgressDialog>
34 #include <QMouseEvent>
35 #include <QPaintEvent>
36 #include <QTime>
37 #include <QGridLayout>
38 #include <QDoubleSpinBox>
39 #include <QLabel>
40 #include <QMovie>
41 #include <QPainter>
42 
43 #include <klfutil.h>
44 
45 
47 
64 {
65  Q_OBJECT
66 public:
67  KLFProgressReporter(int min, int max, QObject *parent = NULL);
69  virtual ~KLFProgressReporter();
70 
71  inline int min() const { return pMin; }
72  inline int max() const { return pMax; }
73 
74 signals:
84  void progress(int progressValue);
85 
90  void finished();
91 
92 public slots:
99  void doReportProgress(int value);
100 
101 private:
102  int pMin;
103  int pMax;
104  bool pFinished;
105 };
106 
172 class KLF_EXPORT KLFProgressDialog : public QProgressDialog
173 {
174  Q_OBJECT
175 public:
177  KLFProgressDialog(QString labelText = QString(), QWidget *parent = NULL);
178 
181  KLFProgressDialog(bool canCancel, QString labelText, QWidget *parent);
182 
183  virtual ~KLFProgressDialog();
184 
185 
186 public slots:
187 
190  virtual void setDescriptiveText(const QString& labelText);
194  virtual void startReportingProgress(KLFProgressReporter *progressReporter,
195  const QString& descriptiveText);
199  virtual void startReportingProgress(KLFProgressReporter *progressReporter);
200 
202  virtual void setValue(int value);
203 
204 protected:
205  void paintEvent(QPaintEvent *event);
206 
207 private:
208  void setup(bool canCancel);
209  void init(const QString& labelText);
210 
211  KLFProgressReporter *pProgressReporter;
212 
213  bool pGotPaintEvent;
214 };
215 
216 
237 class KLF_EXPORT KLFPleaseWaitPopup : public QLabel
238 {
239  Q_OBJECT
240  Q_PROPERTY(bool disableUi READ willDisableUi WRITE setDisableUi) ;
241 public:
260  KLFPleaseWaitPopup(const QString& text, QWidget *callingWidget = NULL, bool alwaysAbove = false);
261  virtual ~KLFPleaseWaitPopup();
262 
263  inline bool willDisableUi() const { return pDisableUi; }
264 
269  virtual void setDisableUi(bool disableUi);
270 
272  virtual bool pleaseWaitShown() const { return pGotPaintEvent; }
273 
276  virtual bool wasUserDiscarded() const { return pDiscarded; }
277 
278 public slots:
280  virtual void showPleaseWait();
281 
282 protected:
283  virtual void mousePressEvent(QMouseEvent *event);
284  virtual void paintEvent(QPaintEvent *event);
285 
286 private:
287  QWidget *pParentWidget;
288  bool pDisableUi;
289  bool pGotPaintEvent;
290  bool pDiscarded;
291 };
292 
293 
306 {
307  Q_OBJECT
308 public:
309  KLFDelayedPleaseWaitPopup(const QString& text, QWidget *callingWidget = NULL);
310  virtual ~KLFDelayedPleaseWaitPopup();
311 
312  virtual void setDelay(int ms);
313 
314 public slots:
315  virtual void process();
316 
317 private:
318  int pDelay;
319  QTime timer;
320 };
321 
322 
339 class KLF_EXPORT KLFEnumComboBox : public QComboBox
340 {
341  Q_OBJECT
342 
343  Q_PROPERTY(int selectedValue READ selectedValue WRITE setSelectedValue)
344 public:
345  KLFEnumComboBox(QWidget *parent = 0);
346  KLFEnumComboBox(const QList<int>& enumValues, const QStringList& enumTitles,
347  QWidget *parent = 0);
348  virtual ~KLFEnumComboBox();
349 
350  int selectedValue() const;
351 
352  QString enumText(int enumValue) const;
353 
354 signals:
355  void selectedValueChanged(int enumValue);
356 
357 public slots:
358  void setSelectedValue(int val);
359 
360  void setEnumValues(const QList<int>& enumValues, const QStringList& enumTitles);
361 
362 private slots:
363  void internalCurrentIndexChanged(int index);
364 
365 private:
366  QList<int> pEnumValueList;
367  QMap<int,QString> pEnumValues;
368  QMap<int,int> pEnumCbxIndexes;
369 };
370 
371 
372 
373 
374 
381 class KLF_EXPORT KLFGridFlowLayout : public QGridLayout
382 {
383  Q_OBJECT
384 public:
385  KLFGridFlowLayout(int columns, QWidget *parent);
386  virtual ~KLFGridFlowLayout() { }
387 
388  virtual int ncolumns() const { return _ncols; }
389 
390  virtual void insertGridFlowWidget(QWidget *w, Qt::Alignment align = 0);
391 
392  void clearAll();
393 
394 protected:
396  int _ncols;
397  int _currow, _curcol;
398 };
399 
400 
401 
402 
404 
412 class KLFWaitAnimationOverlay : public QLabel
413 {
414  Q_OBJECT
415  Q_PROPERTY(QString waitMovie READ waitMovieFileName WRITE setWaitMovie) ;
416  Q_PROPERTY(int widthPercent READ widthPercent WRITE setWidthPercent) ;
417  Q_PROPERTY(int heightPercent READ heightPercent WRITE setHeightPercent) ;
418  Q_PROPERTY(int positionXPercent READ positionXPercent WRITE setPositionXPercent) ;
419  Q_PROPERTY(int positionYPercent READ positionYPercent WRITE setPositionYPercent) ;
420  Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor) ;
421 public:
422  KLFWaitAnimationOverlay(QWidget *parent);
423  virtual ~KLFWaitAnimationOverlay();
424 
425  inline QString waitMovieFileName() const { return (pAnimMovie!=NULL) ? pAnimMovie->fileName() : QString(); }
426 
427  inline int widthPercent() const { return pWidthPercent; }
428  inline int heightPercent() const { return pHeightPercent; }
429  inline int positionXPercent() const { return pPositionXPercent; }
430  inline int positionYPercent() const { return pPositionYPercent; }
431 
432  QColor backgroundColor() const;
433 
434 public slots:
444  virtual void setWaitMovie(QMovie *movie);
447  virtual void setWaitMovie(const QString& file);
448 
450 
461  void setWidthPercent(int widthpercent) { pWidthPercent = widthpercent; }
462 
464 
466  void setHeightPercent(int heightpercent) { pHeightPercent = heightpercent; }
467 
469 
480  void setPositionXPercent(int xpc) { pPositionXPercent = xpc; }
481 
483 
485  void setPositionYPercent(int ypc) { pPositionYPercent = ypc; }
486 
488 
493  void setBackgroundColor(const QColor& c);
494 
496  virtual void startWait();
497 
499  virtual void stopWait();
500 
501 protected:
502  virtual void timerEvent(QTimerEvent *event);
503 
509  virtual QRect calcAnimationLabelGeometry();
510 
511 private:
512  bool pIsWaiting;
513  QMovie *pAnimMovie;
514  int pAnimTimerId;
515 
516  int pWidthPercent;
517  int pHeightPercent;
518  int pPositionXPercent;
519  int pPositionYPercent;
520 };
521 
522 
523 
527 {
528 public:
530  OpenDataOk = 0,
531  OpenDataFailed = 1,
532  OpenDataCantHandle = 2
533  };
534 
535  virtual bool canOpenDropData(const QMimeData * data) = 0;
537  virtual int openDropData(const QMimeData *data) = 0;
538 };
539 
540 
541 
542 
543 
544 
560 KLF_EXPORT void klfDrawGlowedImage(QPainter *painter, const QImage& foreground,
561  const QColor& glow_color = QColor(128, 255, 128, 8),
562  int radius = 4, bool also_draw_image = true);
563 
564 
565 
574 KLF_EXPORT QImage klfImageScaled(const QImage& source, const QSize& newSize);
575 
576 
577 
581 {
582  Q_OBJECT
583 public:
584  KLFWindowGeometryRestorer(QWidget *window);
585  virtual ~KLFWindowGeometryRestorer();
586 
587  virtual bool eventFilter(QObject *obj, QEvent *event);
588 private:
589  QWidget *pWindow;
590 };
591 
592 
595 
596 
597 
598 #endif
int positionXPercent() const
Definition: klfguiutil.h:429
QString waitMovieFileName() const
Definition: klfguiutil.h:425
A Layout that lays out its children in a grid, flowing left to right, top to bottom.
Definition: klfguiutil.h:381
typedef Alignment
KLF_EXPORT void klfHideWindows()
Definition: klfguiutil.cpp:597
int positionYPercent() const
Definition: klfguiutil.h:430
a combo box proposing a list of (integer) enumeration values.
Definition: klfguiutil.h:339
A popup screen inviting the user to wait.
Definition: klfguiutil.h:237
#define KLF_EXPORT
Definition: klfdefs.h:41
Helper class that restores window geometry after show/hide events.
Definition: klfguiutil.h:580
A popup screen inviting user to wait, appearing after a delay.
Definition: klfguiutil.h:305
int max() const
Definition: klfguiutil.h:72
virtual bool pleaseWaitShown() const
Definition: klfguiutil.h:272
int min() const
Definition: klfguiutil.h:71
KLF_EXPORT QImage klfImageScaled(const QImage &source, const QSize &newSize)
Scale image, preserve aspect ratio and meta-information.
Definition: klfguiutil.cpp:512
int heightPercent() const
Definition: klfguiutil.h:428
An animation display.
Definition: klfguiutil.h:412
Object that emits progress information of a (lengthy) operation.
Definition: klfguiutil.h:63
An abstract handler for when data is dropped.
Definition: klfguiutil.h:526
int widthPercent() const
Definition: klfguiutil.h:427
KLF_EXPORT void klfDrawGlowedImage(QPainter *painter, const QImage &foreground, const QColor &glow_color=QColor(128, 255, 128, 8), int radius=4, bool also_draw_image=true)
Draws the given image with a glow effect.
Definition: klfguiutil.cpp:461
virtual bool wasUserDiscarded() const
Definition: klfguiutil.h:276
KLF_EXPORT void klfRestoreWindows()
Definition: klfguiutil.cpp:636
virtual int ncolumns() const
Definition: klfguiutil.h:388
void setHeightPercent(int heightpercent)
Sets the height of this label.
Definition: klfguiutil.h:466
bool willDisableUi() const
Definition: klfguiutil.h:263
void setWidthPercent(int widthpercent)
Sets the width of this label.
Definition: klfguiutil.h:461
void setPositionYPercent(int ypc)
Sets the vertical position of this label relative to the parent widget.
Definition: klfguiutil.h:485
QList< QWidget * > mGridFlowWidgets
Definition: klfguiutil.h:395
virtual ~KLFGridFlowLayout()
Definition: klfguiutil.h:386
A Progress Dialog.
Definition: klfguiutil.h:172
void setPositionXPercent(int xpc)
Sets the horizontal position of this label relative to the parent widget.
Definition: klfguiutil.h:480

Generated by doxygen 1.8.13