A simple Qt based browser with no bullshit that supports PKCS#11 tokens (such as the SuisseID).
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
2.1 KiB

/*! @file
@id $Id$
*/
// 1 2 3 4 5 6 7 8
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
#ifndef __BUTTONLINEEDIT_HXX__
#define __BUTTONLINEEDIT_HXX__
#include <qbrowserlib/log.hxx>
#include <QtGui/QLineEdit>
#include <QtGui/QToolButton>
#include <QtGui/QAction>
#include <QtGui/QStyle>
#include <QtCore/QDebug>
//! @addtogroup qbrowserlib
//! @{
//! A QLineEdit that may have buttons to the right within the lineedit.
class ButtonLineEdit: public QLineEdit {
Q_OBJECT;
public:
ButtonLineEdit(QWidget* p=0): QLineEdit(p) {
TRC;
}
QToolButton* add(QAction* a) {
TRC;
QToolButton* b(new QToolButton(this));
b->setDefaultAction(a);
add(b);
return b;
}
ButtonLineEdit& add(QToolButton* b) {
TRC;
b->setParent(this);
b->setStyleSheet("QToolButton { border: none; padding: 0; }");
b->setCursor(Qt::ArrowCursor);
_buttons.push_back(b);
resizeEvent(0);
return *this;
}
ButtonLineEdit& changeStyleSheet(QString s) {
TRC;
_style = s;
resizeEvent(0);
return *this;
}
static void foreachActionWidget(QAction& a, void(QWidget::*f)()) {
QList<QWidget*> widgets(a.associatedWidgets());
for (QList<QWidget*>::iterator w(widgets.begin()); w!=widgets.end(); ++w)
((*w)->*f)();
}
protected:
void resizeEvent(QResizeEvent*) {
QSize sz;
int frameWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
for (Buttons::iterator it(_buttons.begin());
it!=_buttons.end(); ++it) {
if (sz.isEmpty()) sz = (*it)->sizeHint();
else sz.setWidth(sz.width()+(*it)->sizeHint().width());
(*it)->move(rect().right() - frameWidth - sz.width(),
(rect().bottom() + 1 - (*it)->sizeHint().height())/2);
}
setStyleSheet(QString("QLineEdit { padding-right: %1px; %2 }")
.arg(sz.width() + frameWidth + 1)
.arg(_style));
}
private:
typedef QList<QToolButton*> Buttons;
Buttons _buttons;
QString _style;
};
//! @}
#endif