26 #include <QApplication> 27 #include <QDesktopWidget> 29 #include <QPushButton> 58 qWarning()<<
KLF_FUNC_NAME<<
": Operation is already finished!";
75 : QProgressDialog(parent)
81 : QProgressDialog(parent)
90 void KLFProgressDialog::setup(
bool canCancel)
92 pProgressReporter = NULL;
97 setWindowIcon(
QIcon(
":/pics/klatexformula-16.png"));
98 setWindowTitle(tr(
"Progress"));
99 QPushButton *cbtn =
new QPushButton(tr(
"Cancel"),
this);
100 setCancelButton(cbtn);
101 cbtn->setEnabled(canCancel);
103 void KLFProgressDialog::init(
const QString& labelText)
110 setLabelText(labelText);
111 setFixedSize((
int)(sizeHint().width()*1.3), (
int)(sizeHint().height()*1.1));
114 const QString& descriptiveText)
118 setRange(progressReporter->
min(), progressReporter->
max());
122 if (pProgressReporter != NULL)
123 disconnect(pProgressReporter, 0,
this, SLOT(
setValue(
int)));
125 connect(progressReporter, SIGNAL(progress(
int)),
this, SLOT(
setValue(
int)));
131 setRange(progressReporter->
min(), progressReporter->
max());
134 if (pProgressReporter != NULL)
135 disconnect(pProgressReporter, 0,
this, SLOT(
setValue(
int)));
137 connect(progressReporter, SIGNAL(progress(
int)),
this, SLOT(
setValue(
int)));
144 QProgressDialog::setValue(value);
150 QProgressDialog::paintEvent(event);
157 static Qt::WindowFlags klfpleasewait_flagsForSettings(
bool alwaysAbove)
159 Qt::WindowFlags f = Qt::Window|Qt::SplashScreen|Qt::FramelessWindowHint;
161 f |= Qt::WindowStaysOnTopHint|Qt::X11BypassWindowManagerHint;
166 : QLabel(text, ((parent!=NULL)?parent->window():NULL), klfpleasewait_flagsForSettings(alwaysAbove)),
167 pParentWidget(parent), pDisableUi(false), pGotPaintEvent(false), pDiscarded(false)
173 setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
174 setWindowModality(Qt::ApplicationModal);
176 setAttribute(Qt::WA_StyledBackground,
true);
177 setProperty(
"klfTopLevelWidget",
QVariant(
true));
179 setFrameStyle(QFrame::Panel|QFrame::Sunken);
181 QWidget *pw = parentWidget();
183 setStyleSheet(pw->window()->styleSheet());
185 int w = qMax( (
int)(sizeHint().width() *1.3) , 500 );
186 int h = qMax( (
int)(sizeHint().height()*1.1) , 100 );
188 setWindowOpacity(0.94);
192 if (pDisableUi && pParentWidget != NULL)
193 pParentWidget->setEnabled(
true);
206 QDesktopWidget *dw = QApplication::desktop();
208 desktopSize = dw->screenGeometry(
this).size();
210 desktopSize =
QSize(1024, 768);
212 move(desktopSize.
width()/2 - width()/2, desktopSize.
height()/2 - height()/2);
214 setStyleSheet(styleSheet());
216 if (pDisableUi && pParentWidget != NULL)
217 pParentWidget->setEnabled(
false);
219 while (!pGotPaintEvent)
220 qApp->processEvents();
231 pGotPaintEvent =
true;
232 QLabel::paintEvent(event);
256 qApp->processEvents();
268 connect(
this, SIGNAL(currentIndexChanged(
int)),
this, SLOT(internalCurrentIndexChanged(
int)));
276 connect(
this, SIGNAL(currentIndexChanged(
int)),
this, SLOT(internalCurrentIndexChanged(
int)));
286 klfDbg(
"enumValues="<<enumValues<<
"; enumTitles="<<enumTitles);
288 int savedCurrentIndex = currentIndex();
289 if (enumValues.
size() != enumTitles.
size()) {
290 qWarning()<<
KLF_FUNC_NAME<<
": enum value list and enum title list do not match!";
293 pEnumValueList = enumValues;
296 for (k = 0; k < enumValues.
size(); ++k) {
297 pEnumValues[enumValues[k]] = enumTitles[k];
298 insertItem(k, enumTitles[k],
QVariant(enumValues[k]));
299 pEnumCbxIndexes[enumValues[k]] = k;
301 if (savedCurrentIndex >= 0 && savedCurrentIndex < count())
302 setCurrentIndex(savedCurrentIndex);
308 return itemData(currentIndex()).toInt();
313 if (!pEnumValueList.
contains(enumValue)) {
314 qWarning()<<
KLF_FUNC_NAME<<
": "<<enumValue<<
" is not a registered valid enum value!";
317 return pEnumValues[enumValue];
322 if (!pEnumCbxIndexes.
contains(val)) {
323 qWarning()<<
KLF_FUNC_NAME<<
": "<<val<<
" is not a registered valid enum value!";
326 setCurrentIndex(pEnumCbxIndexes[val]);
329 void KLFEnumComboBox::internalCurrentIndexChanged(
int index)
347 setAlignment(Qt::AlignHCenter|Qt::AlignVCenter);
357 pPositionXPercent = 50;
358 pPositionYPercent = 50;
369 return palette().color(QPalette::Window);
374 if (pAnimMovie != NULL) {
391 setStyleSheet(
QString(
"background-color: rgba(%1,%2,%3,%4)")
402 if (pAnimMovie == NULL)
411 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
423 if (pAnimTimerId >= 0)
424 killTimer(pAnimTimerId);
431 if (event->
timerId() == pAnimTimerId) {
441 QWidget * w = parentWidget();
443 qWarning()<<
KLF_FUNC_NAME<<
": this animation label MUST be used with a parent!";
446 QRect g = w->geometry();
447 QSize sz =
QSize(w->width()*pWidthPercent/100,w->height()*pHeightPercent/100);
449 klfDbg(
"parent geometry: "<<g<<
"; our size="<<sz) ;
462 int r,
bool also_draw_image)
467 if (fg.
format() != QImage::Format_ARGB32_Premultiplied &&
468 fg.
format() != QImage::Format_ARGB32)
471 QRgb glow_color = glowcol.
rgba();
478 QImage glow(fg.
size(), QImage::Format_ARGB32_Premultiplied);
480 qreal ga = qAlpha(glow_color) / qreal(255);
482 for (x = 0; x < fg.
width(); ++x) {
483 for (y = 0; y < fg.
height(); ++y) {
484 qreal ai = qAlpha(fg.
pixel(x,y)) * ga;
487 glow.setPixel(x,y, qRgba(qRed(glow_color)*a, qGreen(glow_color)*a, qBlue(glow_color)*a, ai));
495 for (dx = -r2; dx <= r2; dx += dpr) {
496 for (dy = -r2; dy <= r2; dy += dpr) {
497 if (dx*dx+dy*dy > r2*r2)
503 if (also_draw_image) {
514 QImage img = source.
scaled(newSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
518 for (k = 0; k < keys.
size(); ++k) {
529 #if defined(KLF_WS_X11) 530 QRect g = w->frameGeometry();
532 QRect g = w->geometry();
547 :
QObject(window), pWindow(window)
558 if (obj == pWindow) {
559 if (event->
type() == QEvent::Hide) {
562 }
else if (event->
type() == QEvent::Show) {
564 if ((val = pWindow->property(
"klf_saved_geometry")).isValid())
605 bool allalreadyhidden =
true;
606 QWidgetList wlist = QApplication::topLevelWidgets();
607 foreach (QWidget *w, wlist) {
610 uint wflags = w->windowFlags();
611 klfDbg(
"next widget in line: "<<w<<
", wflags="<<wflags) ;
612 if ((wflags & Qt::Window) == 0) {
615 if (wflags & Qt::X11BypassWindowManagerHint) {
621 klfDbg(
"dealing with widget "<<w) ;
622 bool shown = w->isVisible();
625 klfDbg(
"hiding window "<<w<<
", wflags="<<w->windowFlags()) ;
627 allalreadyhidden =
false;
630 if (!allalreadyhidden) {
632 windowShownStates = states;
639 QWidgetList wlist = QApplication::topLevelWidgets();
640 foreach (QWidget *w, wlist) {
644 if (!w->isVisible()) {
645 klfDbg(
"Restoring window "<<w) ;
646 w->setVisible(windowShownStates[w]);
virtual ~KLFWaitAnimationOverlay()
QImage klfImageScaled(const QImage &source, const QSize &newSize)
Scale image, preserve aspect ratio and meta-information.
bool contains(const Key &key) const
QPixmap currentPixmap() const
virtual ~KLFProgressDialog()
#define KLF_DEBUG_TEE(expr)
Print the value of expression and return it.
KLF_EXPORT void klfHideWindows()
virtual void timerEvent(QTimerEvent *event)
void doReportProgress(int value)
#define klfDbg(streamableItems)
print debug stream items
#define KLF_DEBUG_BLOCK(msg)
Utility to debug the execution of a block.
QString text(const QString &key) const
KLFEnumComboBox(QWidget *parent=0)
QStringList textKeys() const
KLFWaitAnimationOverlay(QWidget *parent)
virtual void setValue(int value)
virtual bool event(QEvent *e)
void selectedValueChanged(int enumValue)
void setText(const QString &key, const QString &text)
void setBackgroundColor(const QColor &c)
Set the label background color.
QRgb pixel(int x, int y) const
void installEventFilter(QObject *filterObj)
KLF_EXPORT void klf_set_window_geometry(QWidget *w, QRect g)
void progress(int progressValue)
void paintEvent(QPaintEvent *event)
void setEnumValues(const QList< int > &enumValues, const QStringList &enumTitles)
QPaintDevice * device() const
Object that emits progress information of a (lengthy) operation.
qreal devicePixelRatioF() const
KLFWindowGeometryRestorer(QWidget *window)
virtual void startReportingProgress(KLFProgressReporter *progressReporter, const QString &descriptiveText)
virtual ~KLFWindowGeometryRestorer()
virtual void startWait()
Display the animation.
void setParent(QObject *parent)
void setCacheMode(CacheMode mode)
bool contains(const T &value) const
bool jumpToFrame(int frameNumber)
virtual void stopWait()
Hide the animation.
void drawImage(const QRectF &target, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags)
KLF_EXPORT void klfRestoreWindows()
QString enumText(int enumValue) const
virtual ~KLFProgressReporter()
KLF_EXPORT void klfDrawGlowedImage(QPainter *p, const QImage &foreground, const QColor &glowcol, int r, bool also_draw_image)
Draws the given image with a glow effect.
int selectedValue() const
void setRelPointSize(int relps)
int nextFrameDelay() const
virtual ~KLFEnumComboBox()
bool contains(const Key &key) const
KLF_EXPORT QRect klf_get_window_geometry(QWidget *w)
virtual QRect calcAnimationLabelGeometry()
virtual bool eventFilter(QObject *obj, QEvent *event)
virtual void setDescriptiveText(const QString &labelText)
void setSelectedValue(int val)
KLFProgressReporter(int min, int max, QObject *parent=NULL)
virtual void setWaitMovie(QMovie *movie)
Set which animation to display while searching.
KLFProgressDialog(QString labelText=QString(), QWidget *parent=NULL)
QImage scaled(int width, int height, Qt::AspectRatioMode aspectRatioMode, Qt::TransformationMode transformMode) const
QColor backgroundColor() const