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.
81 lines
2.2 KiB
81 lines
2.2 KiB
13 years ago
|
/*! @file
|
||
|
|
||
|
@id $Id$
|
||
|
*/
|
||
|
// 1 2 3 4 5 6 7 8
|
||
|
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||
|
|
||
|
#ifndef __BUTTONLINEEDIT_HXX__
|
||
|
#define __BUTTONLINEEDIT_HXX__
|
||
|
|
||
|
#include <QtGui/QLineEdit>
|
||
|
#include <QtGui/QToolButton>
|
||
|
#include <QtGui/QAction>
|
||
|
#include <QtGui/QStyle>
|
||
|
#include <QtCore/QDebug>
|
||
|
|
||
|
#ifndef LOG
|
||
|
#define LOG qDebug()<<__PRETTY_FUNCTION__
|
||
|
#endif
|
||
|
|
||
|
//! @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) {
|
||
|
LOG;
|
||
|
}
|
||
|
QToolButton* add(QAction* a) {
|
||
|
LOG;
|
||
|
QToolButton* b(new QToolButton(this));
|
||
|
b->setDefaultAction(a);
|
||
|
add(b);
|
||
|
return b;
|
||
|
}
|
||
|
ButtonLineEdit& add(QToolButton* b) {
|
||
|
LOG;
|
||
|
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) {
|
||
|
LOG;
|
||
|
_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
|