parent
088163a14d
commit
9ae8812ef5
19 changed files with 377 additions and 233 deletions
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1,15 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#include <buttonlineeditwidgetifc.hxx> |
||||
|
||||
//! @defgroup designer
|
||||
//! @{
|
||||
|
||||
Q_EXPORT_PLUGIN2(buttonlineedit, ButtonLineEditWidgetIfc); |
||||
|
||||
//! @}
|
@ -0,0 +1,77 @@ |
||||
/*! @file
|
||||
|
||||
@id $Id$ |
||||
*/ |
||||
// 1 2 3 4 5 6 7 8
|
||||
// 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
|
||||
#ifndef __BUTTONLINEEDITWIDGETIFC_HXX |
||||
#define __BUTTONLINEEDITWIDGETIFC_HXX |
||||
|
||||
#include <qbrowserlib/buttonlineedit.hxx> |
||||
#include <QtDesigner> |
||||
|
||||
#ifndef LOG |
||||
#define LOG qDebug()<<__PRETTY_FUNCTION__ |
||||
#endif |
||||
|
||||
//! @defgroup designer
|
||||
//! @{
|
||||
|
||||
//! Buttonlineedit widget for Qt Designer
|
||||
class ButtonLineEditWidgetIfc: public QObject, |
||||
public QDesignerCustomWidgetInterface { |
||||
Q_OBJECT; |
||||
Q_INTERFACES(QDesignerCustomWidgetInterface); |
||||
public: |
||||
bool isContainer() const { |
||||
LOG; |
||||
return false; |
||||
} |
||||
QIcon icon() const { |
||||
LOG; |
||||
return QIcon(":/icons/buttonlineedit.png"); |
||||
} |
||||
QString domXml() const { |
||||
LOG; |
||||
return |
||||
QString |
||||
("<ui language=\"c++\" displayname=\"%1\">" |
||||
" <widget class=\"%1\" name=\"%2\"/>" |
||||
" <customwidgets>" |
||||
" <customwidget>" |
||||
" <class>%1</class>" |
||||
" </customwidget>" |
||||
" </customwidgets>" |
||||
"</ui>") |
||||
.arg(name()) |
||||
.arg(name().toLower()); |
||||
} |
||||
QString group() const { |
||||
LOG; |
||||
return "Input Widgets"; |
||||
} |
||||
QString includeFile() const { |
||||
LOG; |
||||
return "qbrowserlib/buttonlineedit.hxx"; |
||||
} |
||||
QString name() const { |
||||
LOG; |
||||
return "ButtonLineEdit"; |
||||
} |
||||
QString toolTip() const { |
||||
LOG; |
||||
return ""; |
||||
} |
||||
QString whatsThis() const { |
||||
LOG; |
||||
return ""; |
||||
} |
||||
QWidget *createWidget(QWidget *parent) { |
||||
LOG; |
||||
return new ButtonLineEdit(parent); |
||||
} |
||||
}; |
||||
|
||||
//! @}
|
||||
#endif |
@ -1,5 +1,6 @@ |
||||
<RCC> |
||||
<qresource prefix="/icons"> |
||||
<file>webview.png</file> |
||||
<file>swisswebview.png</file> |
||||
<file>buttonlineedit.png</file> |
||||
</qresource> |
||||
</RCC> |
||||
|
Before Width: | Height: | Size: 397 B After Width: | Height: | Size: 397 B |
@ -0,0 +1,80 @@ |
||||
/*! @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 |
Loading…
Reference in new issue