Skip to content

Commit

Permalink
A try to fix changing tooltips on toolbar buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Sep 22, 2017
1 parent 32daa90 commit e14fc56
Showing 1 changed file with 23 additions and 28 deletions.
51 changes: 23 additions & 28 deletions src/mainwin_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class PopupActionButton : public QPushButton
~PopupActionButton();

void setIcon(PsiIcon *, bool showText);
void setLabel(QString);
void setLabel(const QString &);

// reimplemented
QSize sizeHint() const;
Expand All @@ -63,16 +63,17 @@ private slots:
void pixmapUpdated();

private:
void update();
void updateText();
void paintEvent(QPaintEvent *);
bool hasToolTip;

private:
PsiIcon *icon;
bool showText;
QString label;
};

PopupActionButton::PopupActionButton(QWidget *parent, const char *name)
: QPushButton(parent), hasToolTip(false), icon(0), showText(true)
: QPushButton(parent), icon(0), showText(true)
{
setObjectName(name);
}
Expand Down Expand Up @@ -106,7 +107,10 @@ void PopupActionButton::setIcon(PsiIcon *i, bool st)
}

icon = i;
showText = st;
if (showText != st) {
showText = st;
updateText();
}

if ( icon ) {
pixmapUpdated();
Expand All @@ -116,28 +120,29 @@ void PopupActionButton::setIcon(PsiIcon *i, bool st)
}
}

void PopupActionButton::setLabel(QString lbl)
void PopupActionButton::setLabel(const QString &lbl)
{
label = lbl;
update();
if (label != lbl) {
label = lbl;
updateText();
}
}

void PopupActionButton::update()
void PopupActionButton::updateText()
{
if(qVersionInt() >= 0x040300)
{
if((showText && !label.isEmpty()) && styleSheet().isEmpty()) {
setStyleSheet("text-align: center");
}
else if((!showText || label.isEmpty()) && styleSheet() == "text-align: center") {
setStyleSheet(QString());
}
if((showText && !label.isEmpty()) && styleSheet().isEmpty()) {
setStyleSheet("text-align: center");
}
else if((!showText || label.isEmpty()) && styleSheet() == "text-align: center") {
setStyleSheet(QString());
}

if (showText) {
QPushButton::setText(label);
QPushButton::setToolTip(label);
} else {
QPushButton::setText("");
QPushButton::setText(QString());
QPushButton::setToolTip(QString());
}
}

Expand All @@ -146,7 +151,6 @@ void PopupActionButton::pixmapUpdated()
QPixmap pix = icon ? icon->pixmap() : QPixmap();
QPushButton::setIcon(pix);
QPushButton::setIconSize(pix.size());
update();
}

void PopupActionButton::paintEvent(QPaintEvent *p)
Expand Down Expand Up @@ -178,10 +182,6 @@ void PopupActionButton::paintEvent(QPaintEvent *p)

// button text larger than what will fit?
if(w1 > w2) {
if( !hasToolTip ) {
setToolTip(label);
hasToolTip = true;
}

// make a string that fits
bool found = false;
Expand Down Expand Up @@ -211,11 +211,6 @@ void PopupActionButton::paintEvent(QPaintEvent *p)
QPushButton::setText(oldtext);
setUpdatesEnabled(true);
}

if( hasToolTip ) {
setToolTip("");
hasToolTip = false;
}
}
}

Expand Down

0 comments on commit e14fc56

Please sign in to comment.