Permalink
Browse files

qtcollider: separate couple of widgets into individual files

  • Loading branch information...
jleben committed May 3, 2012
1 parent 8e6fc8f commit 1db71172f016ba0bf7c6c1ae89021ad583cb8936
View
@@ -28,6 +28,11 @@ set( QT_COLLIDER_HDRS
${QT_COLLIDER_DIR}/QObjectProxy.h
${QT_COLLIDER_DIR}/QWidgetProxy.h
${QT_COLLIDER_DIR}/widgets/BasicWidgets.h
+ ${QT_COLLIDER_DIR}/widgets/QcButton.h
+ ${QT_COLLIDER_DIR}/widgets/QcCheckBox.h
+ ${QT_COLLIDER_DIR}/widgets/QcTextField.h
+ ${QT_COLLIDER_DIR}/widgets/QcListWidget.h
+ ${QT_COLLIDER_DIR}/widgets/QcPopUpMenu.h
${QT_COLLIDER_DIR}/widgets/QcTreeWidget.h
${QT_COLLIDER_DIR}/widgets/QcScrollArea.h
${QT_COLLIDER_DIR}/widgets/QcNumberBox.h
@@ -70,6 +75,11 @@ set( QT_COLLIDER_SRCS
${QT_COLLIDER_DIR}/primitives/prim_QWidget.cpp
${QT_COLLIDER_DIR}/primitives/prim_QPalette.cpp
${QT_COLLIDER_DIR}/widgets/BasicWidgets.cpp
+ ${QT_COLLIDER_DIR}/widgets/QcButton.cpp
+ ${QT_COLLIDER_DIR}/widgets/QcCheckBox.h
+ ${QT_COLLIDER_DIR}/widgets/QcTextField.h
+ ${QT_COLLIDER_DIR}/widgets/QcListWidget.cpp
+ ${QT_COLLIDER_DIR}/widgets/QcPopUpMenu.cpp
${QT_COLLIDER_DIR}/widgets/QcTreeWidget.cpp
${QT_COLLIDER_DIR}/widgets/QcScrollArea.cpp
${QT_COLLIDER_DIR}/widgets/QcAbstractStepValue.cpp
View
@@ -20,6 +20,11 @@
************************************************************************/
#include "QcObjectFactory.h"
+#include "QcWidgetFactory.h"
+
+#include <QLabel>
+
+QC_DECLARE_QWIDGET_FACTORY( QLabel );
namespace QtCollider {
@@ -21,223 +21,10 @@
#include "BasicWidgets.h"
#include "../QcWidgetFactory.h"
-#include "../Common.h"
-
-#include <QApplication>
-#include <QKeyEvent>
-#include <QPainter>
-#ifdef Q_WS_MAC
-# include <QMacStyle>
-#endif
QC_DECLARE_QWIDGET_FACTORY( QcDefaultWidget );
QC_DECLARE_QWIDGET_FACTORY( QcHLayoutWidget );
QC_DECLARE_QWIDGET_FACTORY( QcVLayoutWidget );
-QC_DECLARE_QWIDGET_FACTORY( QLabel );
-QC_DECLARE_QWIDGET_FACTORY( QcTextField );
-QC_DECLARE_QWIDGET_FACTORY( QcCheckBox );
-
-//////////////////////////// QcListWidget //////////////////////////////////////
-
-class QcListWidgetFactory : public QcWidgetFactory<QcListWidget>
-{
- void initialize( QWidgetProxy *p, QcListWidget *l ) {
- p->setMouseEventWidget( l->viewport() );
- }
-};
-
-QC_DECLARE_FACTORY( QcListWidget, QcListWidgetFactory );
-
-QcListWidget::QcListWidget() : _emitAction(true)
-{
- connect( this, SIGNAL( currentItemChanged( QListWidgetItem*, QListWidgetItem* ) ),
- this, SLOT( onCurrentItemChanged() ) );
-}
-
-void QcListWidget::setItems( const VariantList & items )
-{
- _emitAction = false;
- clear();
- Q_FOREACH( QVariant item, items.data )
- addItem( item.toString() );
- setCurrentRow( 0 );
- _emitAction = true;
-}
-
-void QcListWidget::setColors( const VariantList & colors ) const
-{
- int cc = colors.data.count();
- int ic = count();
- for( int i=0; i<cc && i < ic; ++i ) {
- QListWidgetItem *it = item(i);
- QColor color( colors.data[i].value<QColor>() );
- if( color.isValid() ) it->setBackground( color );
- }
-}
-
-void QcListWidget::setCurrentRowWithoutAction( int row )
-{
- bool b = _emitAction;
- _emitAction = false;
- setCurrentRow( row );
- _emitAction = b;
-}
-
-void QcListWidget::onCurrentItemChanged()
-{
- if( _emitAction ) Q_EMIT( action() );
-}
-
-void QcListWidget::keyPressEvent( QKeyEvent *e )
-{
- QListWidget::keyPressEvent( e );
-
- switch (e->key())
- {
- case Qt::Key_Return:
- case Qt::Key_Enter:
- Q_EMIT( returnPressed() );
- e->accept();
- break;
- case Qt::Key_Up:
- case Qt::Key_Down:
- case Qt::Key_Left:
- case Qt::Key_Right:
- case Qt::Key_PageUp:
- case Qt::Key_PageDown:
- case Qt::Key_Home:
- case Qt::Key_End:
- // Prevent propagating to parent when scroller reaches minimum or maximum:
- e->accept();
- default: break;
- }
-}
-
-////////////////////////// QcPopUpMenu /////////////////////////////////////////
-
-QC_DECLARE_QWIDGET_FACTORY(QcPopUpMenu);
-
-QcPopUpMenu::QcPopUpMenu() :
- _changed(false),
- _reactivation(false)
-{
- connect( this, SIGNAL(currentIndexChanged(int)),
- this, SLOT(setChanged()) );
- connect( this, SIGNAL(currentIndexChanged(int)),
- this, SLOT(clearChanged()), Qt::QueuedConnection );
-
- connect( this, SIGNAL(activated(int)), this, SLOT(doAction(int)) );
-}
-
-void QcPopUpMenu::setItems( const VariantList & items )
-{
- clear();
- Q_FOREACH( QVariant item, items.data )
- addItem( item.toString() );
-}
-
-void QcPopUpMenu::doAction( int choice )
-{
- if( _changed || _reactivation )
- Q_EMIT( action() );
-}
-
-/////////////////////////////// QcTextField ////////////////////////////////////
-
-void QcTextField::keyPressEvent( QKeyEvent *e )
-{
- // NOTE: We could use the returnPressed() signal, but that would still
- // propagate the event to parent, which we want to avoid.
- if (e->key() == Qt::Key_Enter || e->key() == Qt::Key_Return)
- Q_EMIT(action());
- else
- QLineEdit::keyPressEvent(e);
-}
-
-/////////////////////////////// QcButton ///////////////////////////////////////
-
-QC_DECLARE_QWIDGET_FACTORY(QcButton);
-
-QcButton::QcButton()
-: currentState(0), defaultPalette( palette() )
-{
- connect( this, SIGNAL(clicked()), this, SLOT(doAction()) );
-}
-
-#ifdef Q_WS_MAC
-bool QcButton::hitButton( const QPoint & pos ) const
-{
- // FIXME: This is a workaround for Qt Bug 15936:
- // incorrect QPushButton hit area.
-
- QMacStyle *macStyle = qobject_cast<QMacStyle *>(style());
-
- if( !macStyle || isFlat() )
- return QAbstractButton::hitButton(pos);
- else
- return QPushButton::hitButton(pos);
-}
-#endif
-
-void QcButton::setStates( const VariantList & statesArg )
-{
- if( !statesArg.data.count() ) return;
-
- states.clear();
-
- Q_FOREACH( QVariant var, statesArg.data ) {
- VariantList stateArg = var.value<VariantList>();
- int count = stateArg.data.size();
- State state;
- if( count >= 1 )
- state.text = stateArg.data[0].toString();
- if( count >= 2 )
- state.textColor = stateArg.data[1].value<QColor>();
- if( count >= 3 )
- state.buttonColor = stateArg.data[2].value<QColor>();
- states.append( state );
- }
- setState( 0 );
-}
-
-void QcButton::setState( int i )
-{
- int c = states.count();
- if( !c ) return;
-
- i = qBound( 0, i, c-1 );
-
- currentState = i;
-
- State state = states[i];
-
- setText( state.text );
-
- QPalette p ( defaultPalette );
-
- if( state.textColor.isValid() )
- p.setColor( QPalette::ButtonText, state.textColor );
- if( state.buttonColor.isValid() )
- p.setColor( QPalette::Button, state.buttonColor );
-
- setPalette( p );
-}
-
-void QcButton::cycleStates()
-{
- if( states.size() < 2 ) return;
- int i = currentState + 1;
- if( i >= states.size() ) i = 0;
- setState( i );
-}
-
-void QcButton::doAction()
-{
- cycleStates();
- Q_EMIT( action((int)QApplication::keyboardModifiers()) );
-}
-
-/////////////////////////////////////////////////////////////////////////
class QcCustomPaintedFactory : public QcWidgetFactory<QcCustomPainted>
{
@@ -22,16 +22,8 @@
#ifndef _WIDGETS_H
#define _WIDGETS_H
-#include "../QcHelper.h"
-#include "../layouts/classic_layouts.hpp"
#include "QcCanvas.h"
-
-#include <QListWidget>
-#include <QComboBox>
-#include <QPushButton>
-#include <QLineEdit>
-#include <QLabel>
-#include <QCheckBox>
+#include "../layouts/classic_layouts.hpp"
class QcDefaultWidget : public QWidget
{
@@ -63,96 +55,7 @@ class QcVLayoutWidget : public QWidget
QtCollider::VLayout l;
};
-
-class QcListWidget : public QListWidget, public QcHelper
-{
- Q_OBJECT
- Q_PROPERTY( VariantList items READ dummyVariantList WRITE setItems );
- Q_PROPERTY( VariantList colors READ dummyVariantList WRITE setColors );
- Q_PROPERTY( int currentRow READ currentRow WRITE setCurrentRowWithoutAction )
-
- public:
- QcListWidget();
- void setItems( const VariantList & );
- void setColors( const VariantList & ) const;
- void setCurrentRowWithoutAction( int );
- Q_SIGNALS:
- void action();
- void returnPressed();
- private Q_SLOTS:
- void onCurrentItemChanged();
- protected:
- virtual void keyPressEvent( QKeyEvent * );
- private:
- bool _emitAction;
-};
-
-class QcPopUpMenu : public QComboBox, public QcHelper
-{
- Q_OBJECT
- Q_PROPERTY( VariantList items READ dummyVariantList WRITE setItems );
- Q_PROPERTY( bool reactivationEnabled READ reactivationEnabled WRITE setReactivationEnabled )
-
- public:
- QcPopUpMenu();
- bool reactivationEnabled() const { return _reactivation; }
- void setReactivationEnabled( bool b ) { _reactivation = b; }
- Q_SIGNALS:
- void action();
- private Q_SLOTS:
- void doAction(int);
- void setChanged() { _changed = true; }
- void clearChanged() { _changed = false; }
- private:
- void setItems( const VariantList & );
- bool _changed;
- bool _reactivation;
-};
-
-class QcTextField : public QLineEdit
-{
- Q_OBJECT
-
- public:
- QcTextField() {}
- protected:
- virtual void keyPressEvent( QKeyEvent * );
- Q_SIGNALS:
- void action();
-};
-
-class QcButton : public QPushButton, public QcHelper
-{
- Q_OBJECT
- Q_PROPERTY( VariantList states READ dummyVariantList WRITE setStates );
- Q_PROPERTY( int value READ getValue WRITE setValue );
- public:
- QcButton();
- Q_SIGNALS:
- void action(int);
- protected:
-#ifdef Q_WS_MAC
- bool hitButton( const QPoint & ) const;
-#endif
- private Q_SLOTS:
- void doAction();
- private:
- struct State {
- QString text;
- QColor textColor;
- QColor buttonColor;
- };
- void setStates( const VariantList & );
- void setValue( int val ) { setState( val ); }
- int getValue() const { return currentState; }
- void setState( int );
- void cycleStates();
- QList<State> states;
- int currentState;
- QPalette defaultPalette;
-};
-
-class QcCustomPainted : public QcCanvas, QcHelper
+class QcCustomPainted : public QcCanvas
{
Q_OBJECT
public:
@@ -166,20 +69,4 @@ class QcCustomPainted : public QcCanvas, QcHelper
QtCollider::DefaultLayout l;
};
-class QcCheckBox : public QCheckBox
-{
- Q_OBJECT
- Q_PROPERTY( bool value READ value WRITE setValue );
-
- public:
- QcCheckBox() {
- connect( this, SIGNAL(clicked()), this, SIGNAL(action()) );
- }
- Q_SIGNALS:
- void action();
- private:
- bool value() { return isChecked(); }
- void setValue( bool val ) { setChecked(val); }
-};
-
#endif // _WIDGETS_H
Oops, something went wrong.

0 comments on commit 1db7117

Please sign in to comment.