From 334c75bf93f525d1edf55a3c74425e77c614999a Mon Sep 17 00:00:00 2001 From: omy Date: Mon, 12 May 2014 18:00:31 +0400 Subject: [PATCH] Extended QtxListAction with resize ability. --- src/Qtx/QtxListAction.cxx | 146 ++++++++++++++++++++++++++++++++++++-- src/Qtx/QtxListAction.h | 5 ++ 2 files changed, 147 insertions(+), 4 deletions(-) diff --git a/src/Qtx/QtxListAction.cxx b/src/Qtx/QtxListAction.cxx index 43cf17c9d..7a70887da 100755 --- a/src/Qtx/QtxListAction.cxx +++ b/src/Qtx/QtxListAction.cxx @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -74,6 +75,100 @@ protected: } }; +/*! + \class QtxListAction::SizeGrip + \internal + \brief Custom size grip widget. +*/ +class QtxListAction::SizeGrip : public QSizeGrip +{ +public: + SizeGrip(QWidget* parent); + ~SizeGrip(); + +protected: + + virtual void mousePressEvent (QMouseEvent * e); + virtual void mouseMoveEvent (QMouseEvent * e); + virtual void mouseReleaseEvent(QMouseEvent * e); + +private: + QPoint myPos; + bool myMouseClick; + +}; + +/*! + \brief Constructor. +*/ +QtxListAction::SizeGrip::SizeGrip(QWidget* parent) +: QSizeGrip( parent ), + myMouseClick( false ) +{ +} + +/*! + \brief Destructor. +*/ +QtxListAction::SizeGrip::~SizeGrip() +{ +} + +/*! + \brief Reimplementation of mouse press event on the SizeGrip area + \param e event +*/ +void QtxListAction::SizeGrip::mousePressEvent(QMouseEvent * e) + { + if (e->button() != Qt::LeftButton) + { + QWidget::mousePressEvent(e); + return; + } + else + { + myPos = e->pos(); + myMouseClick = true; + } + }; + +/*! + \brief Reimplementation of mouse move event on the SizeGrip area + \param e event +*/ +void QtxListAction::SizeGrip::mouseMoveEvent(QMouseEvent * e) + { + if (myMouseClick) + { + QWidget* aWidget = this->parentWidget(); + while (aWidget && aWidget->parentWidget()) + aWidget = aWidget->parentWidget(); + + aWidget->setGeometry(aWidget->frameGeometry().topLeft().x(), + aWidget->frameGeometry().topLeft().y(), + aWidget->frameGeometry().width() + e->pos().x() - myPos.x(), + aWidget->frameGeometry().height() + e->pos().y() - myPos.y()); + } + }; + +/*! + \brief Reimplementation of mouse release event on the SizeGrip area + \param e event +*/ +void QtxListAction::SizeGrip::mouseReleaseEvent(QMouseEvent * e) + { + if (e->button() != Qt::LeftButton) + { + QWidget::mouseReleaseEvent(e); + myMouseClick = false; + return; + } + else + { + myMouseClick = false; + } + }; + /*! \class QtxListAction::ListFrame \internal @@ -109,6 +204,9 @@ public: virtual void setVisible( bool ); + void setHorizontalScrollBarPolicy ( Qt::ScrollBarPolicy ); + void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy ); + protected: virtual void keyPressEvent( QKeyEvent* ); @@ -116,7 +214,7 @@ private: void accept(); void updateComment(); void setNames( const QStringList& ); - void removePostedEvens( QObject*, int ); + void removePostedEvents( QObject*, int ); private: QListWidget* myList; @@ -165,11 +263,19 @@ QtxListAction::ListFrame::ListFrame( QtxListAction* a, QWidget* parent ) myComment = new QLabel( main ); myComment->setFrameStyle( QFrame::Panel | QFrame::Sunken ); + myComment->setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); myComment->setAlignment( Qt::AlignCenter ); myMultipleComment = "%1"; base->addWidget( myList ); - base->addWidget( myComment ); + + SizeGrip* aGrip = new SizeGrip( main ); + aGrip->setSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum); + QHBoxLayout* bottom = new QHBoxLayout ( this ); + bottom->addWidget( myComment, 1 ); + bottom->addWidget( aGrip, 0, Qt::AlignBottom | Qt::AlignRight ); + + base->addLayout ( bottom ); } /*! @@ -188,6 +294,22 @@ void QtxListAction::ListFrame::clear() setNames( myNames ); } +/*! + \brief Sets horizontal scroll bar policy +*/ +void QtxListAction::ListFrame::setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy thePolicy) +{ + myList->setHorizontalScrollBarPolicy (thePolicy); +} + +/*! + \brief Sets vertical scroll bar policy +*/ +void QtxListAction::ListFrame::setVerticalScrollBarPolicy (Qt::ScrollBarPolicy thePolicy) +{ + myList->setVerticalScrollBarPolicy (thePolicy); +} + /*! \brief Add names to the list. @@ -534,7 +656,7 @@ void QtxListAction::ListFrame::setSelected( const int lastSel ) myList->scrollToItem( myList->item( item ) ); myList->clearFocus(); - removePostedEvens( myList->viewport(), ScrollEvent::Scroll ); + removePostedEvents( myList->viewport(), ScrollEvent::Scroll ); updateComment(); } @@ -544,7 +666,7 @@ void QtxListAction::ListFrame::setSelected( const int lastSel ) \param o object \param type event type to be filtered */ -void QtxListAction::ListFrame::removePostedEvens( QObject* o, int type ) +void QtxListAction::ListFrame::removePostedEvents( QObject* o, int type ) { class Filter : public QObject { @@ -715,6 +837,22 @@ void QtxListAction::addNames( const QStringList& names, bool clear ) onChanged(); } +/*! + \brief Sets horizontal scroll bar policy +*/ +void QtxListAction::setHorizontalScrollBarPolicy (Qt::ScrollBarPolicy thePolicy) +{ + myFrame->setHorizontalScrollBarPolicy (thePolicy); +} + +/*! + \brief Sets vertical scroll bar policy +*/ +void QtxListAction::setVerticalScrollBarPolicy (Qt::ScrollBarPolicy thePolicy) +{ + myFrame->setVerticalScrollBarPolicy (thePolicy); +} + /*! \brief Get maximum numer of lines shown without activation of vertical scroll bar. \return number of lines diff --git a/src/Qtx/QtxListAction.h b/src/Qtx/QtxListAction.h index 8643d6184..2c6f31e66 100755 --- a/src/Qtx/QtxListAction.h +++ b/src/Qtx/QtxListAction.h @@ -40,6 +40,7 @@ class QTX_EXPORT QtxListAction : public QtxAction class ListFrame; class ListWidget; + class SizeGrip; class ScrollEvent; public: @@ -70,6 +71,9 @@ public: void setLinesNumber( const int ); void setCharsNumber( const int ); + void setHorizontalScrollBarPolicy( Qt::ScrollBarPolicy ); + void setVerticalScrollBarPolicy ( Qt::ScrollBarPolicy ); + signals: void triggered( int ); @@ -90,6 +94,7 @@ private: ListFrame* myFrame; //!< list of actions shown as submenu friend class QtxListAction::ListFrame; + friend class QtxListAction::SizeGrip; }; #ifdef WIN32 -- 2.39.2