Skip to content

Commit

Permalink
sclang: Add backend support for QToolbar, QMenu, and QAction
Browse files Browse the repository at this point in the history
  • Loading branch information
scztt committed Jul 10, 2016
1 parent cbfcd57 commit f780d16
Show file tree
Hide file tree
Showing 9 changed files with 287 additions and 10 deletions.
2 changes: 2 additions & 0 deletions QtCollider/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ set( QT_COLLIDER_HDRS
${QT_COLLIDER_DIR}/widgets/QcListWidget.h
${QT_COLLIDER_DIR}/widgets/QcPopUpMenu.h
${QT_COLLIDER_DIR}/widgets/QcTreeWidget.h
${QT_COLLIDER_DIR}/widgets/QcMenu.h
${QT_COLLIDER_DIR}/widgets/QcScrollArea.h
${QT_COLLIDER_DIR}/widgets/QcNumberBox.h
${QT_COLLIDER_DIR}/widgets/QcSlider.h
Expand Down Expand Up @@ -97,6 +98,7 @@ set( QT_COLLIDER_SRCS
${QT_COLLIDER_DIR}/widgets/QcListWidget.cpp
${QT_COLLIDER_DIR}/widgets/QcPopUpMenu.cpp
${QT_COLLIDER_DIR}/widgets/QcTreeWidget.cpp
${QT_COLLIDER_DIR}/widgets/QcMenu.cpp
${QT_COLLIDER_DIR}/widgets/QcScrollArea.cpp
${QT_COLLIDER_DIR}/widgets/QcAbstractStepValue.cpp
${QT_COLLIDER_DIR}/widgets/QcNumberBox.cpp
Expand Down
2 changes: 2 additions & 0 deletions QtCollider/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ namespace QtCollider {
QC_DO_SYMBOL(TreeViewItem); \
QC_DO_SYMBOL(Gradient); \
QC_DO_SYMBOL(HiliteGradient); \
QC_DO_SYMBOL(AbstractAction); \
QC_DO_SYMBOL(Menu); \
QC_DO_SYMBOL(View); \
QC_DO_SYMBOL(Image);

Expand Down
4 changes: 4 additions & 0 deletions QtCollider/factories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ static void doLoadFactories ()
QC_ADD_FACTORY( QcWaveform );
QC_ADD_FACTORY( QcTextEdit );
QC_ADD_FACTORY( QcTreeWidget );
QC_ADD_FACTORY( QcMenu );
QC_ADD_FACTORY( QcToolBar );
QC_ADD_FACTORY( QcAction );
QC_ADD_FACTORY( QcWidgetAction );
QC_ADD_FACTORY( WebView );
QC_ADD_FACTORY( QcWindow );
QC_ADD_FACTORY( QcScrollWindow );
Expand Down
14 changes: 14 additions & 0 deletions QtCollider/metatype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ void MetaType::initAll()
qRegisterMetaType< QVector<double> >();
qRegisterMetaType< QVector<int> >();
qRegisterMetaType<SharedImage>();
qRegisterMetaType<QcAction*>();
qRegisterMetaType<QcWidgetAction*>();
qRegisterMetaType<QcMenu*>();
qRegisterMetaType<QcToolBar*>();
qRegisterMetaType<QList<QAction*> >();

gMetaTypes.reserve(20);

Expand All @@ -70,6 +75,9 @@ void MetaType::initAll()
qc_init_metatype<PyrObject*>();
qc_init_metatype<QcTreeWidget::ItemPtr>();
qc_init_metatype<SharedImage>();
qc_init_metatype<QMenu*>();
qc_init_metatype<QAction*>();
qc_init_metatype<QList<QAction*>>();
qc_init_metatype< QVector<double> >();
qc_init_metatype< QVector<int> >();
qc_init_metatype< QVariantList >();
Expand Down Expand Up @@ -125,6 +133,12 @@ MetaType *MetaType::find( PyrSlot *slot )
else if( isKindOfSlot( slot, SC_CLASS(QPalette) ) ) {
return metaType<QPalette>();
}
else if( isKindOfSlot( slot, SC_CLASS(AbstractAction) ) ) {
return metaType<QAction*>();
}
else if( isKindOfSlot( slot, SC_CLASS(Menu) ) ) {
return metaType<QMenu*>();
}
else if( isKindOfSlot( slot, SC_CLASS(View) ) || isKindOfSlot( slot, SC_CLASS(ScrollCanvas) ) ) {
return metaType<QWidget*>();
}
Expand Down
18 changes: 8 additions & 10 deletions QtCollider/type_codec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,7 @@ QFont TypeCodec<QFont>::safeRead( PyrSlot *slot )
else
return QFont();
}



QPalette TypeCodec<QPalette>::read( PyrSlot *slot )
{
QPalette *p = QPALETTE_FROM_OBJECT(slotRawObject(slot));
Expand Down Expand Up @@ -285,8 +284,7 @@ QObjectProxy * TypeCodec<QObjectProxy*>::safeRead( PyrSlot *slot )
if( !isKindOfSlot( slot, SC_CLASS(QObject) ) ) return 0;
return read(slot);
}



void TypeCodec<QObject*>::write( PyrSlot *slot, QObject * obj )
{
QObjectProxy *proxy = QObjectProxy::fromObject(obj);
Expand Down Expand Up @@ -381,7 +379,7 @@ static QVector<numeric_type> toNumericVector( PyrObject *obj )

return vector;
}

template<typename numeric_type>
static void setNumeric( PyrSlot *, numeric_type );

Expand Down Expand Up @@ -415,8 +413,7 @@ static void setNumericVector( PyrSlot *slot, const QVector<numeric_type> & vec )
++s;
}
}



QVector<double> TypeCodec< QVector<double> >::read( PyrSlot *slot )
{
return toNumericVector<double>(slotRawObject(slot));
Expand All @@ -440,7 +437,6 @@ void TypeCodec< QVector<int> >::write( PyrSlot *slot, const QVector<int> & vec )
setNumericVector<int>( slot, vec );
}


QcTreeWidget::ItemPtr TypeCodec<QcTreeWidget::ItemPtr>::read( PyrSlot *slot )
{
PyrSlot *ptrSlot = slotRawObject(slot)->slots+0;
Expand All @@ -460,7 +456,7 @@ void TypeCodec<QcTreeWidget::ItemPtr>::write( PyrSlot *slot, const QcTreeWidget:
QcTreeWidget::Item::initialize( gMainVMGlobals, obj, item );
SetObject( slot, obj );
}

SharedImage TypeCodec<SharedImage>::read( PyrSlot * slot )
{
SharedImage *ptr = reinterpret_cast<SharedImage*>( slotRawPtr( slotRawObject(slot)->slots+0 ) );
Expand All @@ -480,4 +476,6 @@ void TypeCodec<SharedImage>::write( PyrSlot *slot, SharedImage image )
qWarning("WARNING: QtCollider: writing SharedImage to PyrSlot not supported.");
}

} // namespace QtCollider
}

// namespace QtCollider
2 changes: 2 additions & 0 deletions QtCollider/type_codec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#define QT_COLLIDER_TYPE_CODEC_INCLUDED

#include "widgets/QcTreeWidget.h"
#include "widgets/QcMenu.h"
#include "image.h"

#include <PyrSlot.h>
Expand All @@ -41,6 +42,7 @@
#include <QFont>
#include <QPalette>
#include <QWidget>
#include <QLayout>
#include <QVector>
#include <QVariantList>

Expand Down
9 changes: 9 additions & 0 deletions QtCollider/widgets/BasicWidgets.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
#define _WIDGETS_H

#include "QcCanvas.h"
#include "QcMenu.h"
#include "../layouts/classic_layouts.hpp"
#include "image_painter.h"

class QcSimpleWidget : public QWidget
{
Q_OBJECT
Q_PROPERTY( QColor background READ background WRITE setBackground );
Q_PROPERTY( QList<QAction*> actions READ actions());

public:
const QColor & background() const { return _bkg; }
Expand All @@ -39,7 +41,14 @@ class QcSimpleWidget : public QWidget
int tileMode, double opacity );
Q_INVOKABLE
void removeBackgroundImage() { _bkg_image.clear(); update(); }

Q_INVOKABLE void addAction(QAction* action) { QWidget::addAction(action); }

Q_INVOKABLE void removeAction(QAction* action) { QWidget::removeAction(action); }

Q_INVOKABLE void insertAction(QAction* before, QAction* action)
{ QWidget::insertAction(before, action); }

protected:
virtual void paintEvent( QPaintEvent * );

Expand Down
118 changes: 118 additions & 0 deletions QtCollider/widgets/QcMenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/************************************************************************
*
* Copyright 2011-2012 Jakob Leben ([email protected])
*
* This file is part of SuperCollider Qt GUI.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
************************************************************************/

#include "QcMenu.h"
#include "../QcWidgetFactory.h"

#include <PyrKernel.h>

#include <QKeyEvent>

QC_DECLARE_QWIDGET_FACTORY(QcMenu);
QC_DECLARE_QWIDGET_FACTORY(QcToolBar);
QC_DECLARE_QOBJECT_FACTORY(QcAction);
QC_DECLARE_QOBJECT_FACTORY(QcWidgetAction);

QcMenu::QcMenu()
: QMenu(NULL)
{
setAttribute(Qt::WA_DeleteOnClose, false);
}

void QcMenu::popup(QPointF pos, QAction* action)
{
QMenu::popup(QPoint(pos.x(), pos.y()), action);
}

void QcMenu::addAction(QAction* action)
{
if (action) {
QMenu::addAction(action);
} else {
QMenu::addSeparator();
}
}

void QcMenu::insertAction(QAction* beforeAction, QAction* action)
{
if (action) {
QMenu::insertAction(beforeAction, action);
} else {
QMenu::insertSeparator(beforeAction);
}
}

void QcMenu::removeAction(QAction* action)
{
if (action) {
QMenu::removeAction(action);
}
}

void QcToolBar::addAction(QAction* action)
{
if (action) {
QToolBar::addAction(action);
} else {
QToolBar::addSeparator();
}
}

void QcToolBar::insertAction(QAction* beforeAction, QAction* action)
{
if (action) {
QToolBar::insertAction(beforeAction, action);
} else {
QToolBar::insertSeparator(beforeAction);
}
}

void QcToolBar::removeAction(QAction* action)
{
if (action) {
QToolBar::removeAction(action);
}
}

QcAction::QcAction()
: QAction(NULL)
{
}

QcWidgetAction::QcWidgetAction()
: QWidgetAction(NULL)
{
}

void QcAction::setIcon(const QtCollider::SharedImage & image)
{
if (image) {
QIcon icon(QPixmap::fromImage(image->image()));
QAction::setIcon(icon);
} else {
QAction::setIcon(QIcon());
}
}

QcToolBar::QcToolBar()
: QToolBar()
{
}
Loading

0 comments on commit f780d16

Please sign in to comment.