26 #include <QApplication>
27 #include <QDesktopWidget>
29 #include <QPushButton>
57 qWarning()<<
KLF_FUNC_NAME<<
": Operation is already finished!";
89 void KLFProgressDialog::setup(
bool canCancel)
91 pProgressReporter = NULL;
96 setWindowIcon(
QIcon(
":/pics/klatexformula-16.png"));
97 setWindowTitle(tr(
"Progress"));
100 cbtn->setEnabled(canCancel);
102 void KLFProgressDialog::init(
const QString& labelText)
109 setLabelText(labelText);
110 setFixedSize((
int)(
sizeHint().width()*1.3), (
int)(
sizeHint().height()*1.1));
113 const QString& descriptiveText)
121 if (pProgressReporter != NULL)
122 disconnect(pProgressReporter, 0,
this, SLOT(
setValue(
int)));
124 connect(progressReporter, SIGNAL(progress(
int)),
this, SLOT(
setValue(
int)));
133 if (pProgressReporter != NULL)
134 disconnect(pProgressReporter, 0,
this, SLOT(
setValue(
int)));
136 connect(progressReporter, SIGNAL(progress(
int)),
this, SLOT(
setValue(
int)));
143 QProgressDialog::setValue(value);
149 QProgressDialog::paintEvent(event);
158 Qt::WindowFlags f = Qt::Window|Qt::SplashScreen|Qt::FramelessWindowHint;
160 f |= Qt::WindowStaysOnTopHint|Qt::X11BypassWindowManagerHint;
166 pParentWidget(parent), pDisableUi(false), pGotPaintEvent(false), pDiscarded(false)
173 setWindowModality(Qt::ApplicationModal);
175 setAttribute(Qt::WA_StyledBackground,
true);
176 setProperty(
"klfTopLevelWidget",
QVariant(
true));
178 setFrameStyle(QFrame::Panel|QFrame::Sunken);
182 setStyleSheet(pw->
window()->styleSheet());
184 int w = qMax( (
int)(sizeHint().width() *1.3) , 500 );
185 int h = qMax( (
int)(sizeHint().height()*1.1) , 100 );
187 setWindowOpacity(0.94);
191 if (pDisableUi && pParentWidget != NULL)
192 pParentWidget->setEnabled(
true);
209 desktopSize =
QSize(1024, 768);
211 move(desktopSize.
width()/2 - width()/2, desktopSize.
height()/2 - height()/2);
213 setStyleSheet(styleSheet());
215 if (pDisableUi && pParentWidget != NULL)
216 pParentWidget->setEnabled(
false);
218 while (!pGotPaintEvent)
219 qApp->processEvents();
230 pGotPaintEvent =
true;
231 QLabel::paintEvent(event);
255 qApp->processEvents();
267 connect(
this, SIGNAL(
currentIndexChanged(
int)),
this, SLOT(internalCurrentIndexChanged(
int)));
275 connect(
this, SIGNAL(
currentIndexChanged(
int)),
this, SLOT(internalCurrentIndexChanged(
int)));
285 klfDbg(
"enumValues="<<enumValues<<
"; enumTitles="<<enumTitles);
287 int savedCurrentIndex = currentIndex();
288 if (enumValues.
size() != enumTitles.size()) {
289 qWarning()<<
KLF_FUNC_NAME<<
": enum value list and enum title list do not match!";
292 pEnumValueList = enumValues;
295 for (k = 0; k < enumValues.
size(); ++k) {
296 pEnumValues[enumValues[k]] = enumTitles[k];
298 pEnumCbxIndexes[enumValues[k]] = k;
300 if (savedCurrentIndex >= 0 && savedCurrentIndex < count())
301 setCurrentIndex(savedCurrentIndex);
307 return itemData(currentIndex()).toInt();
312 if (!pEnumValueList.
contains(enumValue)) {
313 qWarning()<<
KLF_FUNC_NAME<<
": "<<enumValue<<
" is not a registered valid enum value!";
316 return pEnumValues[enumValue];
321 if (!pEnumCbxIndexes.
contains(val)) {
322 qWarning()<<
KLF_FUNC_NAME<<
": "<<val<<
" is not a registered valid enum value!";
325 setCurrentIndex(pEnumCbxIndexes[val]);
328 void KLFEnumComboBox::internalCurrentIndexChanged(
int index)
356 pPositionXPercent = 50;
357 pPositionYPercent = 50;
368 return palette().color(QPalette::Window);
373 if (pAnimMovie != NULL) {
377 pAnimMovie->setParent(
this);
383 m->setCacheMode(QMovie::CacheAll);
390 setStyleSheet(
QString(
"background-color: rgba(%1,%2,%3,%4)")
401 if (pAnimMovie == NULL)
410 qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
422 if (pAnimTimerId >= 0)
423 killTimer(pAnimTimerId);
430 if (event->
timerId() == pAnimTimerId) {
442 qWarning()<<
KLF_FUNC_NAME<<
": this animation label MUST be used with a parent!";
445 QRect g = w->geometry();
446 QSize sz =
QSize(w->width()*pWidthPercent/100,w->height()*pHeightPercent/100);
448 klfDbg(
"parent geometry: "<<g<<
"; our size="<<sz) ;
461 int r,
bool also_draw_image)
464 if (fg.
format() != QImage::Format_ARGB32_Premultiplied &&
465 fg.
format() != QImage::Format_ARGB32)
468 QRgb glow_color = glowcol.
rgba();
469 int ga = qAlpha(glow_color);
471 QImage glow(fg.
size(), QImage::Format_ARGB32_Premultiplied);
473 for (x = 0; x < fg.
width(); ++x) {
474 for (y = 0; y < fg.
height(); ++y) {
475 int a = qAlpha(fg.
pixel(x,y)) * ga / 255;
477 glow.
setPixel(x,y, qRgba(qRed(glow_color)*a/255, qGreen(glow_color)*a/255, qBlue(glow_color)*a/255, a));
481 for (x = -r; x <= r; ++x) {
482 for (y = -r; y <= r; ++y) {
void doReportProgress(int value)
setPointSize(int pointSize)
QColor backgroundColor() const
virtual void startReportingProgress(KLFProgressReporter *progressReporter, const QString &descriptiveText)
void paintEvent(QPaintEvent *event)
KLFProgressReporter(int min, int max, QObject *parent=NULL)
#define KLF_DEBUG_TEE(expr)
#define klfDbg(streamableItems)
void setBackgroundColor(const QColor &c)
Set the label background color.
#define KLF_DEBUG_BLOCK(msg)
pixel(const QPoint &position)
insertItem(int index, const QString &text, const QVariant &userData=QVariant()
virtual void setValue(int value)
void setEnumValues(const QList< int > &enumValues, const QStringList &enumTitles)
virtual ~KLFEnumComboBox()
virtual ~KLFProgressReporter()
KLFWaitAnimationOverlay(QWidget *parent)
virtual void setDescriptiveText(const QString &labelText)
virtual ~KLFProgressDialog()
setAlignment(int alignment)
KLFProgressDialog(QString labelText=QString(), QWidget *parent=NULL)
setRange(int minimum, int maximum)
KLFEnumComboBox(QWidget *parent=0)
static Qt::WindowFlags klfpleasewait_flagsForSettings(bool alwaysAbove)
itemData(int index, int role=Qt::UserRole)
QString enumText(int enumValue) const
jumpToFrame(int frameNumber)
virtual void timerEvent(QTimerEvent *event)
setPixel(const QPoint &position, uint index_or_rgb)
drawImage(const QRectF &target, const QImage &image, const QRectF &source, Qt::ImageConversionFlags flags=Qt::AutoColor)
void selectedValueChanged(int enumValue)
virtual ~KLFWaitAnimationOverlay()
void setSelectedValue(int val)
virtual void setWaitMovie(QMovie *movie)
Set which animation to display while searching.
virtual void stopWait()
Hide the animation.
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.
virtual QRect calcAnimationLabelGeometry()
int selectedValue() const
virtual void startWait()
Display the animation.
Object that emits progress information of a (lengthy) operation.
currentIndexChanged(int index)
void progress(int progressValue)