+ unify DLL export defines to namespace names
git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5000 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
20
src/Tools/plugins/widget/FreeCAD_widgets.sln
Normal file
20
src/Tools/plugins/widget/FreeCAD_widgets.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C++ Express 2005
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "FreeCAD_widgets", "FreeCAD_widgets.vcproj", "{50CDC58F-0FF6-3CFA-BF66-E79DA98E7DF0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{50CDC58F-0FF6-3CFA-BF66-E79DA98E7DF0}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{50CDC58F-0FF6-3CFA-BF66-E79DA98E7DF0}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{50CDC58F-0FF6-3CFA-BF66-E79DA98E7DF0}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{50CDC58F-0FF6-3CFA-BF66-E79DA98E7DF0}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
871
src/Tools/plugins/widget/customwidgets.cpp
Normal file
871
src/Tools/plugins/widget/customwidgets.cpp
Normal file
@@ -0,0 +1,871 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
#include <QCursor>
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
#include <QStyleOptionButton>
|
||||
#include <QStylePainter>
|
||||
|
||||
#include "customwidgets.h"
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
|
||||
UrlLabel::UrlLabel ( QWidget * parent, Qt::WFlags f )
|
||||
: QLabel("TextLabel", parent, f)
|
||||
{
|
||||
_url = "http://localhost";
|
||||
setToolTip(this->_url);
|
||||
}
|
||||
|
||||
UrlLabel::~UrlLabel()
|
||||
{
|
||||
}
|
||||
|
||||
void UrlLabel::enterEvent ( QEvent * )
|
||||
{
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
}
|
||||
|
||||
void UrlLabel::leaveEvent ( QEvent * )
|
||||
{
|
||||
setCursor(Qt::ArrowCursor);
|
||||
}
|
||||
|
||||
void UrlLabel::mouseReleaseEvent ( QMouseEvent * )
|
||||
{
|
||||
QMessageBox::information(this, "Browser",
|
||||
QString("This starts your browser with url %1").arg(_url));
|
||||
}
|
||||
|
||||
QString UrlLabel::url() const
|
||||
{
|
||||
return this->_url;
|
||||
}
|
||||
|
||||
void UrlLabel::setUrl(const QString& u)
|
||||
{
|
||||
this->_url = u;
|
||||
setToolTip(this->_url);
|
||||
}
|
||||
|
||||
FileChooser::FileChooser( QWidget *parent )
|
||||
: QWidget( parent ), md( File ), _filter( QString::null )
|
||||
{
|
||||
QHBoxLayout *layout = new QHBoxLayout( this );
|
||||
layout->setMargin( 0 );
|
||||
layout->setSpacing( 6 );
|
||||
|
||||
lineEdit = new QLineEdit( this );
|
||||
layout->addWidget( lineEdit );
|
||||
|
||||
connect(lineEdit, SIGNAL(textChanged(const QString &)),
|
||||
this, SIGNAL(fileNameChanged(const QString &)));
|
||||
|
||||
button = new QPushButton( "...", this );
|
||||
button->setFixedWidth(2*button->fontMetrics().width( " ... " ));
|
||||
layout->addWidget( button );
|
||||
|
||||
connect(button, SIGNAL(clicked()), this, SLOT(chooseFile()));
|
||||
|
||||
setFocusProxy( lineEdit );
|
||||
}
|
||||
|
||||
FileChooser::~FileChooser()
|
||||
{
|
||||
}
|
||||
|
||||
QString FileChooser::fileName() const
|
||||
{
|
||||
return lineEdit->text();
|
||||
}
|
||||
|
||||
void FileChooser::setFileName( const QString &fn )
|
||||
{
|
||||
lineEdit->setText( fn );
|
||||
}
|
||||
|
||||
void FileChooser::chooseFile()
|
||||
{
|
||||
QString fn;
|
||||
if ( mode() == File )
|
||||
fn = QFileDialog::getOpenFileName(this, tr("Select a file"),
|
||||
lineEdit->text(), _filter);
|
||||
else
|
||||
fn = QFileDialog::getExistingDirectory(this, tr("Select a directory"),
|
||||
lineEdit->text() );
|
||||
|
||||
if (!fn.isEmpty()) {
|
||||
lineEdit->setText(fn);
|
||||
emit fileNameSelected(fn);
|
||||
}
|
||||
}
|
||||
|
||||
FileChooser::Mode FileChooser::mode() const
|
||||
{
|
||||
return md;
|
||||
}
|
||||
|
||||
void FileChooser::setMode( Mode m )
|
||||
{
|
||||
md = m;
|
||||
}
|
||||
|
||||
QString FileChooser::filter() const
|
||||
{
|
||||
return _filter;
|
||||
}
|
||||
|
||||
void FileChooser::setFilter ( const QString& filter )
|
||||
{
|
||||
_filter = filter;
|
||||
}
|
||||
|
||||
void FileChooser::setButtonText( const QString& txt )
|
||||
{
|
||||
button->setText( txt );
|
||||
int w1 = 2*button->fontMetrics().width(txt);
|
||||
int w2 = 2*button->fontMetrics().width(" ... ");
|
||||
button->setFixedWidth((w1 > w2 ? w1 : w2));
|
||||
}
|
||||
|
||||
QString FileChooser::buttonText() const
|
||||
{
|
||||
return button->text();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
PrefFileChooser::PrefFileChooser ( QWidget * parent )
|
||||
: FileChooser(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefFileChooser::~PrefFileChooser()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefFileChooser::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefFileChooser::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefFileChooser::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefFileChooser::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
AccelLineEdit::AccelLineEdit ( QWidget * parent )
|
||||
: QLineEdit(parent)
|
||||
{
|
||||
setText(tr("none"));
|
||||
}
|
||||
|
||||
void AccelLineEdit::keyPressEvent ( QKeyEvent * e)
|
||||
{
|
||||
QString txt;
|
||||
setText(tr("none"));
|
||||
|
||||
int key = e->key();
|
||||
Qt::KeyboardModifiers state = e->modifiers();
|
||||
|
||||
if ( key == Qt::Key_Control )
|
||||
return;
|
||||
else if ( key == Qt::Key_Shift )
|
||||
return;
|
||||
else if ( key == Qt::Key_Alt )
|
||||
return;
|
||||
else if ( state == Qt::NoModifier && key == Qt::Key_Backspace )
|
||||
return; // clears the edit field
|
||||
|
||||
switch( state )
|
||||
{
|
||||
case Qt::ControlModifier:
|
||||
{
|
||||
QKeySequence key(Qt::CTRL+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::AltModifier:
|
||||
{
|
||||
QKeySequence key(Qt::ALT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::ShiftModifier:
|
||||
{
|
||||
QKeySequence key(Qt::SHIFT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::ControlModifier+Qt::AltModifier:
|
||||
{
|
||||
QKeySequence key(Qt::CTRL+Qt::ALT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::ControlModifier+Qt::ShiftModifier:
|
||||
{
|
||||
QKeySequence key(Qt::CTRL+Qt::SHIFT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::ShiftModifier+Qt::AltModifier:
|
||||
{
|
||||
QKeySequence key(Qt::SHIFT+Qt::ALT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
case Qt::ControlModifier+Qt::AltModifier+Qt::ShiftModifier:
|
||||
{
|
||||
QKeySequence key(Qt::CTRL+Qt::ALT+Qt::SHIFT+key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
QKeySequence key(key);
|
||||
txt += (QString)(key);
|
||||
setText(txt);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
CommandIconView::CommandIconView ( QWidget * parent )
|
||||
: QListWidget(parent)
|
||||
{
|
||||
connect(this, SIGNAL (currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
|
||||
this, SLOT (onSelectionChanged(QListWidgetItem *, QListWidgetItem *)) );
|
||||
}
|
||||
|
||||
CommandIconView::~CommandIconView ()
|
||||
{
|
||||
}
|
||||
|
||||
void CommandIconView::startDrag ( Qt::DropActions /*supportedActions*/ )
|
||||
{
|
||||
QList<QListWidgetItem*> items = selectedItems();
|
||||
QByteArray itemData;
|
||||
QDataStream dataStream(&itemData, QIODevice::WriteOnly);
|
||||
|
||||
QPixmap pixmap;
|
||||
dataStream << items.count();
|
||||
for (QList<QListWidgetItem*>::ConstIterator it = items.begin(); it != items.end(); ++it) {
|
||||
if (it == items.begin())
|
||||
pixmap = qVariantValue<QPixmap>((*it)->data(Qt::UserRole));
|
||||
dataStream << (*it)->text();
|
||||
}
|
||||
|
||||
QMimeData *mimeData = new QMimeData;
|
||||
mimeData->setData("text/x-action-items", itemData);
|
||||
|
||||
QDrag *drag = new QDrag(this);
|
||||
drag->setMimeData(mimeData);
|
||||
drag->setHotSpot(QPoint(pixmap.width()/2, pixmap.height()/2));
|
||||
drag->setPixmap(pixmap);
|
||||
drag->start(Qt::MoveAction);
|
||||
}
|
||||
|
||||
void CommandIconView::onSelectionChanged(QListWidgetItem * item, QListWidgetItem *)
|
||||
{
|
||||
if (item)
|
||||
emitSelectionChanged(item->toolTip());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class UnsignedValidator : public QValidator
|
||||
{
|
||||
public:
|
||||
UnsignedValidator( QObject * parent );
|
||||
UnsignedValidator( uint minimum, uint maximum, QObject * parent );
|
||||
~UnsignedValidator();
|
||||
|
||||
QValidator::State validate( QString &, int & ) const;
|
||||
|
||||
void setBottom( uint );
|
||||
void setTop( uint );
|
||||
virtual void setRange( uint bottom, uint top );
|
||||
|
||||
uint bottom() const { return b; }
|
||||
uint top() const { return t; }
|
||||
|
||||
private:
|
||||
uint b, t;
|
||||
};
|
||||
|
||||
UnsignedValidator::UnsignedValidator( QObject * parent )
|
||||
: QValidator( parent )
|
||||
{
|
||||
b = 0;
|
||||
t = UINT_MAX;
|
||||
}
|
||||
|
||||
UnsignedValidator::UnsignedValidator( uint minimum, uint maximum, QObject * parent )
|
||||
: QValidator( parent )
|
||||
{
|
||||
b = minimum;
|
||||
t = maximum;
|
||||
}
|
||||
|
||||
UnsignedValidator::~UnsignedValidator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QValidator::State UnsignedValidator::validate( QString & input, int & ) const
|
||||
{
|
||||
QString stripped;// = input.stripWhiteSpace();
|
||||
if ( stripped.isEmpty() )
|
||||
return Intermediate;
|
||||
bool ok;
|
||||
uint entered = input.toUInt( &ok );
|
||||
if ( !ok )
|
||||
return Invalid;
|
||||
else if ( entered < b )
|
||||
return Intermediate;
|
||||
else if ( entered > t )
|
||||
return Invalid;
|
||||
// else if ( entered < b || entered > t )
|
||||
// return Invalid;
|
||||
else
|
||||
return Acceptable;
|
||||
}
|
||||
|
||||
void UnsignedValidator::setRange( uint minimum, uint maximum )
|
||||
{
|
||||
b = minimum;
|
||||
t = maximum;
|
||||
}
|
||||
|
||||
void UnsignedValidator::setBottom( uint bottom )
|
||||
{
|
||||
setRange( bottom, top() );
|
||||
}
|
||||
|
||||
void UnsignedValidator::setTop( uint top )
|
||||
{
|
||||
setRange( bottom(), top );
|
||||
}
|
||||
|
||||
class UIntSpinBoxPrivate
|
||||
{
|
||||
public:
|
||||
UnsignedValidator * mValidator;
|
||||
|
||||
UIntSpinBoxPrivate() : mValidator(0)
|
||||
{
|
||||
}
|
||||
uint mapToUInt( int v ) const
|
||||
{
|
||||
uint ui;
|
||||
if ( v == INT_MIN ) {
|
||||
ui = 0;
|
||||
}
|
||||
else if ( v == INT_MAX ) {
|
||||
ui = UINT_MAX;
|
||||
}
|
||||
else if ( v < 0 ) {
|
||||
v -= INT_MIN; ui = (uint)v;
|
||||
}
|
||||
else {
|
||||
ui = (uint)v; ui -= INT_MIN;
|
||||
}
|
||||
return ui;
|
||||
}
|
||||
int mapToInt( uint v ) const
|
||||
{
|
||||
int in;
|
||||
if ( v == UINT_MAX ) {
|
||||
in = INT_MAX;
|
||||
}
|
||||
else if ( v == 0 ) {
|
||||
in = INT_MIN;
|
||||
}
|
||||
else if ( v > INT_MAX ) {
|
||||
v += INT_MIN; in = (int)v;
|
||||
}
|
||||
else {
|
||||
in = v; in += INT_MIN;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
UIntSpinBox::UIntSpinBox (QWidget* parent)
|
||||
: QSpinBox (parent)
|
||||
{
|
||||
d = new UIntSpinBoxPrivate;
|
||||
d->mValidator = new UnsignedValidator(this->minimum(), this->maximum(), this);
|
||||
connect(this, SIGNAL(valueChanged(int)),
|
||||
this, SLOT(valueChange(int)));
|
||||
setRange(0, 99);
|
||||
setValue(0);
|
||||
updateValidator();
|
||||
}
|
||||
|
||||
UIntSpinBox::~UIntSpinBox()
|
||||
{
|
||||
delete d->mValidator;
|
||||
delete d; d = 0;
|
||||
}
|
||||
|
||||
void UIntSpinBox::setRange(uint minVal, uint maxVal)
|
||||
{
|
||||
int iminVal = d->mapToInt(minVal);
|
||||
int imaxVal = d->mapToInt(maxVal);
|
||||
QSpinBox::setRange(iminVal, imaxVal);
|
||||
updateValidator();
|
||||
}
|
||||
|
||||
QValidator::State UIntSpinBox::validate (QString & input, int & pos) const
|
||||
{
|
||||
return d->mValidator->validate(input, pos);
|
||||
}
|
||||
|
||||
uint UIntSpinBox::value() const
|
||||
{
|
||||
return d->mapToUInt(QSpinBox::value());
|
||||
}
|
||||
|
||||
void UIntSpinBox::setValue(uint value)
|
||||
{
|
||||
QSpinBox::setValue(d->mapToInt(value));
|
||||
}
|
||||
|
||||
void UIntSpinBox::valueChange(int value)
|
||||
{
|
||||
valueChanged(d->mapToUInt(value));
|
||||
}
|
||||
|
||||
uint UIntSpinBox::minimum() const
|
||||
{
|
||||
return d->mapToUInt(QSpinBox::minimum());
|
||||
}
|
||||
|
||||
void UIntSpinBox::setMinimum(uint minVal)
|
||||
{
|
||||
uint maxVal = maximum();
|
||||
if (maxVal < minVal)
|
||||
maxVal = minVal;
|
||||
setRange(minVal, maxVal);
|
||||
}
|
||||
|
||||
uint UIntSpinBox::maximum() const
|
||||
{
|
||||
return d->mapToUInt(QSpinBox::maximum());
|
||||
}
|
||||
|
||||
void UIntSpinBox::setMaximum(uint maxVal)
|
||||
{
|
||||
uint minVal = minimum();
|
||||
if (minVal > maxVal)
|
||||
minVal = maxVal;
|
||||
setRange(minVal, maxVal);
|
||||
}
|
||||
|
||||
QString UIntSpinBox::textFromValue (int v) const
|
||||
{
|
||||
uint val = d->mapToUInt(v);
|
||||
QString s;
|
||||
s.setNum(val);
|
||||
return s;
|
||||
}
|
||||
|
||||
int UIntSpinBox::valueFromText (const QString & text) const
|
||||
{
|
||||
bool ok;
|
||||
QString s = text;
|
||||
uint newVal = s.toUInt(&ok);
|
||||
if (!ok && !(prefix().isEmpty() && suffix().isEmpty())) {
|
||||
s = cleanText();
|
||||
newVal = s.toUInt(&ok);
|
||||
}
|
||||
|
||||
return d->mapToInt(newVal);
|
||||
}
|
||||
|
||||
void UIntSpinBox::updateValidator()
|
||||
{
|
||||
d->mValidator->setRange(this->minimum(), this->maximum());
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefSpinBox::PrefSpinBox ( QWidget * parent )
|
||||
: QSpinBox(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefSpinBox::~PrefSpinBox()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefSpinBox::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefSpinBox::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefSpinBox::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefSpinBox::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefDoubleSpinBox::PrefDoubleSpinBox ( QWidget * parent )
|
||||
: QDoubleSpinBox(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefDoubleSpinBox::~PrefDoubleSpinBox()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefDoubleSpinBox::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefDoubleSpinBox::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefDoubleSpinBox::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefDoubleSpinBox::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
ColorButton::ColorButton(QWidget* parent)
|
||||
: QPushButton( parent ), _allowChange(true), _drawFrame(true)
|
||||
{
|
||||
_col = palette().color(QPalette::Active,QPalette::Midlight);
|
||||
connect( this, SIGNAL( clicked() ), SLOT( onChooseColor() ));
|
||||
}
|
||||
|
||||
ColorButton::~ColorButton()
|
||||
{
|
||||
}
|
||||
|
||||
void ColorButton::setColor( const QColor& c )
|
||||
{
|
||||
_col = c;
|
||||
update();
|
||||
}
|
||||
|
||||
QColor ColorButton::color() const
|
||||
{
|
||||
return _col;
|
||||
}
|
||||
|
||||
void ColorButton::setAllowChangeColor(bool ok)
|
||||
{
|
||||
_allowChange = ok;
|
||||
}
|
||||
|
||||
bool ColorButton::allowChangeColor() const
|
||||
{
|
||||
return _allowChange;
|
||||
}
|
||||
|
||||
void ColorButton::setDrawFrame(bool ok)
|
||||
{
|
||||
_drawFrame = ok;
|
||||
}
|
||||
|
||||
bool ColorButton::drawFrame() const
|
||||
{
|
||||
return _drawFrame;
|
||||
}
|
||||
|
||||
void ColorButton::paintEvent ( QPaintEvent * e )
|
||||
{
|
||||
// first paint the complete button
|
||||
QPushButton::paintEvent(e);
|
||||
|
||||
// repaint the rectangle area
|
||||
QPalette::ColorGroup group = isEnabled() ? hasFocus() ? QPalette::Active : QPalette::Inactive : QPalette::Disabled;
|
||||
QColor pen = palette().color(group,QPalette::ButtonText);
|
||||
{
|
||||
QPainter paint(this);
|
||||
paint.setPen( pen );
|
||||
|
||||
if (_drawFrame) {
|
||||
paint.setBrush(QBrush(_col));
|
||||
paint.drawRect(5, 5, width()-10, height()-10);
|
||||
} else {
|
||||
paint.fillRect(5, 5, width()-10, height()-10, QBrush(_col));
|
||||
}
|
||||
}
|
||||
|
||||
// overpaint the rectangle to paint icon and text
|
||||
QStyleOptionButton opt;
|
||||
opt.init(this);
|
||||
opt.text = text();
|
||||
opt.icon = icon();
|
||||
opt.iconSize = iconSize();
|
||||
|
||||
QStylePainter p(this);
|
||||
p.drawControl(QStyle::CE_PushButtonLabel, opt);
|
||||
}
|
||||
|
||||
void ColorButton::onChooseColor()
|
||||
{
|
||||
if (!_allowChange)
|
||||
return;
|
||||
QColor c = QColorDialog::getColor( _col, this );
|
||||
if ( c.isValid() )
|
||||
{
|
||||
setColor( c );
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
PrefColorButton::PrefColorButton ( QWidget * parent )
|
||||
: ColorButton(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefColorButton::~PrefColorButton()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefColorButton::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefColorButton::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefColorButton::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefColorButton::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefLineEdit::PrefLineEdit ( QWidget * parent )
|
||||
: QLineEdit(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefLineEdit::~PrefLineEdit()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefLineEdit::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefLineEdit::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefLineEdit::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefLineEdit::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefComboBox::PrefComboBox ( QWidget * parent )
|
||||
: QComboBox(parent)
|
||||
{
|
||||
setEditable(false);
|
||||
}
|
||||
|
||||
PrefComboBox::~PrefComboBox()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefComboBox::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefComboBox::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefComboBox::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefComboBox::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefCheckBox::PrefCheckBox ( QWidget * parent )
|
||||
: QCheckBox(parent)
|
||||
{
|
||||
setText("CheckBox");
|
||||
}
|
||||
|
||||
PrefCheckBox::~PrefCheckBox()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefCheckBox::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefCheckBox::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefCheckBox::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefCheckBox::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefRadioButton::PrefRadioButton ( QWidget * parent )
|
||||
: QRadioButton(parent)
|
||||
{
|
||||
setText("RadioButton");
|
||||
}
|
||||
|
||||
PrefRadioButton::~PrefRadioButton()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefRadioButton::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefRadioButton::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefRadioButton::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefRadioButton::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
PrefSlider::PrefSlider ( QWidget * parent )
|
||||
: QSlider(parent)
|
||||
{
|
||||
}
|
||||
|
||||
PrefSlider::~PrefSlider()
|
||||
{
|
||||
}
|
||||
|
||||
QByteArray PrefSlider::entryName () const
|
||||
{
|
||||
return m_sPrefName;
|
||||
}
|
||||
|
||||
QByteArray PrefSlider::paramGrpPath () const
|
||||
{
|
||||
return m_sPrefGrp;
|
||||
}
|
||||
|
||||
void PrefSlider::setEntryName ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefName = name;
|
||||
}
|
||||
|
||||
void PrefSlider::setParamGrpPath ( const QByteArray& name )
|
||||
{
|
||||
m_sPrefGrp = name;
|
||||
}
|
||||
432
src/Tools/plugins/widget/customwidgets.h
Normal file
432
src/Tools/plugins/widget/customwidgets.h
Normal file
@@ -0,0 +1,432 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef GUI_CUSTOMWIDGETS_H
|
||||
#define GUI_CUSTOMWIDGETS_H
|
||||
|
||||
#include <QButtonGroup>
|
||||
#include <QWidget>
|
||||
#include <QLineEdit>
|
||||
#include <QListWidget>
|
||||
#include <QPushButton>
|
||||
#include <QRadioButton>
|
||||
#include <QSpinBox>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QComboBox>
|
||||
#include <QCheckBox>
|
||||
#include <QLabel>
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
class UrlLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY( QString url READ url WRITE setUrl)
|
||||
|
||||
public:
|
||||
UrlLabel ( QWidget * parent = 0, Qt::WFlags f = 0 );
|
||||
virtual ~UrlLabel();
|
||||
|
||||
QString url() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setUrl( const QString &u );
|
||||
|
||||
protected:
|
||||
void enterEvent ( QEvent * );
|
||||
void leaveEvent ( QEvent * );
|
||||
void mouseReleaseEvent ( QMouseEvent * );
|
||||
|
||||
private:
|
||||
QString _url;
|
||||
};
|
||||
|
||||
/**
|
||||
* There is a bug in QtDesigner of Qt version 4.0, 4.1 and 4.2. If a class declaration
|
||||
* is inside a namespace and it uses the Q_ENUMS macro then QtDesigner doesn't handle
|
||||
* the enum(s) correctly in its property editor. This bug is fixed since Qt 4.3.0.
|
||||
*/
|
||||
class FileChooser : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_ENUMS( Mode )
|
||||
Q_PROPERTY( Mode mode READ mode WRITE setMode )
|
||||
Q_PROPERTY( QString fileName READ fileName WRITE setFileName )
|
||||
Q_PROPERTY( QString filter READ filter WRITE setFilter )
|
||||
Q_PROPERTY( QString buttonText READ buttonText WRITE setButtonText )
|
||||
|
||||
public:
|
||||
enum Mode { File, Directory };
|
||||
|
||||
FileChooser (QWidget *parent = 0);
|
||||
virtual ~FileChooser();
|
||||
|
||||
|
||||
QString filter() const;
|
||||
QString fileName() const;
|
||||
Mode mode() const;
|
||||
QString buttonText() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void setFileName( const QString &fn );
|
||||
void setMode( Mode m );
|
||||
void setFilter ( const QString & );
|
||||
void setButtonText ( const QString & );
|
||||
|
||||
Q_SIGNALS:
|
||||
void fileNameChanged( const QString & );
|
||||
void fileNameSelected( const QString & );
|
||||
|
||||
private Q_SLOTS:
|
||||
void chooseFile();
|
||||
|
||||
private:
|
||||
QLineEdit *lineEdit;
|
||||
QPushButton *button;
|
||||
Mode md;
|
||||
QString _filter;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefFileChooser : public FileChooser
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefFileChooser ( QWidget * parent = 0 );
|
||||
virtual ~PrefFileChooser();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class AccelLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
AccelLineEdit ( QWidget * parent=0 );
|
||||
|
||||
protected:
|
||||
void keyPressEvent ( QKeyEvent * e);
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class CommandIconView : public QListWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CommandIconView ( QWidget * parent = 0 );
|
||||
virtual ~CommandIconView ();
|
||||
|
||||
protected:
|
||||
void startDrag ( Qt::DropActions supportedActions );
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onSelectionChanged( QListWidgetItem * item, QListWidgetItem * );
|
||||
|
||||
Q_SIGNALS:
|
||||
void emitSelectionChanged( const QString& );
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
class UIntSpinBoxPrivate;
|
||||
class UIntSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_OVERRIDE( uint maximum READ maximum WRITE setMaximum )
|
||||
Q_OVERRIDE( uint minimum READ minimum WRITE setMinimum )
|
||||
Q_OVERRIDE( uint value READ value WRITE setValue )
|
||||
|
||||
public:
|
||||
UIntSpinBox ( QWidget* parent );
|
||||
virtual ~UIntSpinBox();
|
||||
|
||||
void setRange( uint minVal, uint maxVal );
|
||||
uint value() const;
|
||||
virtual QValidator::State validate ( QString & input, int & pos ) const;
|
||||
uint minimum() const;
|
||||
void setMinimum( uint value );
|
||||
uint maximum() const;
|
||||
void setMaximum( uint value );
|
||||
|
||||
Q_SIGNALS:
|
||||
void valueChanged( uint value );
|
||||
|
||||
public Q_SLOTS:
|
||||
void setValue( uint value );
|
||||
|
||||
private Q_SLOTS:
|
||||
void valueChange( int value );
|
||||
|
||||
protected:
|
||||
virtual QString textFromValue ( int v ) const;
|
||||
virtual int valueFromText ( const QString & text ) const;
|
||||
|
||||
private:
|
||||
void updateValidator();
|
||||
UIntSpinBoxPrivate * d;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------
|
||||
|
||||
class PrefSpinBox : public QSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefSpinBox ( QWidget * parent = 0 );
|
||||
virtual ~PrefSpinBox();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class ColorButton : public QPushButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QColor color READ color WRITE setColor )
|
||||
Q_PROPERTY( bool allowChangeColor READ allowChangeColor WRITE setAllowChangeColor )
|
||||
Q_PROPERTY( bool drawFrame READ drawFrame WRITE setDrawFrame )
|
||||
|
||||
public:
|
||||
ColorButton( QWidget* parent = 0 );
|
||||
~ColorButton();
|
||||
|
||||
void setColor( const QColor& );
|
||||
QColor color() const;
|
||||
|
||||
void setAllowChangeColor(bool);
|
||||
bool allowChangeColor() const;
|
||||
|
||||
void setDrawFrame(bool);
|
||||
bool drawFrame() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
virtual void onChooseColor();
|
||||
|
||||
Q_SIGNALS:
|
||||
void changed();
|
||||
|
||||
protected:
|
||||
void paintEvent ( QPaintEvent* );
|
||||
|
||||
private:
|
||||
QColor _col;
|
||||
bool _allowChange;
|
||||
bool _drawFrame;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefColorButton : public ColorButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefColorButton ( QWidget * parent = 0 );
|
||||
virtual ~PrefColorButton();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefDoubleSpinBox : public QDoubleSpinBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefDoubleSpinBox ( QWidget * parent = 0 );
|
||||
virtual ~PrefDoubleSpinBox();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefLineEdit : public QLineEdit
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefLineEdit ( QWidget * parent = 0 );
|
||||
virtual ~PrefLineEdit();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefComboBox : public QComboBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefComboBox ( QWidget * parent = 0 );
|
||||
virtual ~PrefComboBox();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefCheckBox : public QCheckBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefCheckBox ( QWidget * parent = 0 );
|
||||
virtual ~PrefCheckBox();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefRadioButton : public QRadioButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefRadioButton ( QWidget * parent = 0 );
|
||||
virtual ~PrefRadioButton();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
class PrefSlider : public QSlider
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY( QByteArray prefEntry READ entryName WRITE setEntryName )
|
||||
Q_PROPERTY( QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath )
|
||||
|
||||
public:
|
||||
PrefSlider ( QWidget * parent = 0 );
|
||||
virtual ~PrefSlider();
|
||||
|
||||
QByteArray entryName () const;
|
||||
QByteArray paramGrpPath () const;
|
||||
void setEntryName ( const QByteArray& name );
|
||||
void setParamGrpPath ( const QByteArray& name );
|
||||
|
||||
private:
|
||||
QByteArray m_sPrefName;
|
||||
QByteArray m_sPrefGrp;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // GUI_CUSTOMWIDGETS_H
|
||||
1058
src/Tools/plugins/widget/plugin.cpp
Normal file
1058
src/Tools/plugins/widget/plugin.cpp
Normal file
File diff suppressed because it is too large
Load Diff
40
src/Tools/plugins/widget/plugin.h
Normal file
40
src/Tools/plugins/widget/plugin.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <QtDesigner/QDesignerContainerExtension>
|
||||
#include <QtDesigner/QDesignerCustomWidgetCollectionInterface>
|
||||
|
||||
#include <QtCore/qplugin.h>
|
||||
#include <QtGui/QIcon>
|
||||
|
||||
class QDesignerFormEditorInterface;
|
||||
|
||||
class CustomWidgetPlugin : public QObject, public QDesignerCustomWidgetCollectionInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
|
||||
public:
|
||||
CustomWidgetPlugin(QObject *parent = 0);
|
||||
QList<QDesignerCustomWidgetInterface *> customWidgets () const;
|
||||
};
|
||||
|
||||
10
src/Tools/plugins/widget/plugin.pro
Normal file
10
src/Tools/plugins/widget/plugin.pro
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
TEMPLATE = lib
|
||||
CONFIG += designer plugin
|
||||
TARGET = FreeCAD_widgets
|
||||
DEPENDPATH += .
|
||||
INCLUDEPATH += .
|
||||
|
||||
# Input
|
||||
HEADERS += customwidgets.h plugin.h
|
||||
SOURCES += customwidgets.cpp plugin.cpp
|
||||
231
src/Tools/plugins/widget/wizard.cpp
Normal file
231
src/Tools/plugins/widget/wizard.cpp
Normal file
@@ -0,0 +1,231 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2007 Werner Mayer <wmayer@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include <QtGui>
|
||||
|
||||
#include "wizard.h"
|
||||
|
||||
Wizard::Wizard(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
textLabel = new QLabel();
|
||||
|
||||
topLine = new QFrame();
|
||||
topLine->setFrameShape(QFrame::HLine);
|
||||
topLine->setFrameShadow(QFrame::Sunken);
|
||||
bottomLine = new QFrame();
|
||||
bottomLine->setFrameShape(QFrame::HLine);
|
||||
bottomLine->setFrameShadow(QFrame::Sunken);
|
||||
|
||||
_cancelButton = new QPushButton(tr("Cancel"));
|
||||
_backButton = new QPushButton(tr("< &Back"));
|
||||
_backButton->setDisabled(true);
|
||||
_nextButton = new QPushButton(tr("Next >"));
|
||||
_nextButton->setDisabled(true);
|
||||
_finishButton = new QPushButton(tr("&Finish"));
|
||||
_finishButton->setDisabled(true);
|
||||
|
||||
connect(_cancelButton, SIGNAL(clicked()),
|
||||
this, SLOT(reject()));
|
||||
connect(_backButton, SIGNAL(clicked()),
|
||||
this, SLOT(backButtonClicked()));
|
||||
connect(_nextButton, SIGNAL(clicked()),
|
||||
this, SLOT(nextButtonClicked()));
|
||||
connect(_finishButton, SIGNAL(clicked()),
|
||||
this, SLOT(accept()));
|
||||
|
||||
buttonLayout = new QHBoxLayout;
|
||||
buttonLayout->addStretch(1);
|
||||
buttonLayout->addWidget(_cancelButton);
|
||||
buttonLayout->addWidget(_backButton);
|
||||
buttonLayout->addWidget(_nextButton);
|
||||
buttonLayout->addWidget(_finishButton);
|
||||
|
||||
stackWidget = new QStackedWidget();
|
||||
|
||||
mainLayout = new QVBoxLayout();
|
||||
mainLayout->addWidget(textLabel);
|
||||
mainLayout->addWidget(topLine);
|
||||
mainLayout->addWidget(stackWidget);
|
||||
mainLayout->addWidget(bottomLine);
|
||||
mainLayout->addLayout(buttonLayout);
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
QSize Wizard::sizeHint() const
|
||||
{
|
||||
return QSize(200, 150);
|
||||
}
|
||||
|
||||
void Wizard::addPage(QWidget *page)
|
||||
{
|
||||
insertPage(count(), page);
|
||||
}
|
||||
|
||||
void Wizard::removePage(int index)
|
||||
{
|
||||
QWidget *widget = stackWidget->widget(index);
|
||||
stackWidget->removeWidget(widget);
|
||||
|
||||
index = currentIndex();
|
||||
_backButton->setEnabled(index > 0);
|
||||
_nextButton->setEnabled(index < count()-1);
|
||||
}
|
||||
|
||||
int Wizard::count() const
|
||||
{
|
||||
return stackWidget->count();
|
||||
}
|
||||
|
||||
int Wizard::currentIndex() const
|
||||
{
|
||||
return stackWidget->currentIndex();
|
||||
}
|
||||
|
||||
void Wizard::insertPage(int index, QWidget *page)
|
||||
{
|
||||
page->setParent(stackWidget);
|
||||
|
||||
stackWidget->insertWidget(index, page);
|
||||
|
||||
QString title = page->windowTitle();
|
||||
if (title.isEmpty()) {
|
||||
title = tr("Page %1").arg(stackWidget->count());
|
||||
page->setWindowTitle(title);
|
||||
}
|
||||
|
||||
if (currentIndex() == index)
|
||||
textLabel->setText(title);
|
||||
|
||||
int current = currentIndex();
|
||||
_backButton->setEnabled(current > 0);
|
||||
_nextButton->setEnabled(current < count()-1);
|
||||
}
|
||||
|
||||
void Wizard::backButtonClicked()
|
||||
{
|
||||
int index = currentIndex();
|
||||
if (index > 0)
|
||||
setCurrentIndex(index-1);
|
||||
}
|
||||
|
||||
void Wizard::nextButtonClicked()
|
||||
{
|
||||
int index = currentIndex();
|
||||
if (index < count()-1)
|
||||
setCurrentIndex(index+1);
|
||||
}
|
||||
|
||||
QPushButton* Wizard::backButton() const
|
||||
{
|
||||
return _backButton;
|
||||
}
|
||||
|
||||
QPushButton* Wizard::nextButton() const
|
||||
{
|
||||
return _nextButton;
|
||||
}
|
||||
|
||||
void Wizard::setCurrentIndex(int index)
|
||||
{
|
||||
if (index != currentIndex()) {
|
||||
stackWidget->setCurrentIndex(index);
|
||||
textLabel->setText(stackWidget->currentWidget()->windowTitle());
|
||||
_backButton->setEnabled(index > 0);
|
||||
_nextButton->setEnabled(index < count()-1);
|
||||
emit currentIndexChanged(index);
|
||||
}
|
||||
}
|
||||
|
||||
QWidget* Wizard::widget(int index)
|
||||
{
|
||||
return stackWidget->widget(index);
|
||||
}
|
||||
|
||||
QString Wizard::pageTitle() const
|
||||
{
|
||||
return stackWidget->currentWidget()->windowTitle();
|
||||
}
|
||||
|
||||
void Wizard::setPageTitle(QString const &newTitle)
|
||||
{
|
||||
stackWidget->currentWidget()->setWindowTitle(newTitle);
|
||||
textLabel->setText(newTitle);
|
||||
emit pageTitleChanged(newTitle);
|
||||
}
|
||||
|
||||
WizardExtension::WizardExtension(Wizard *widget, QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
myWidget = widget;
|
||||
}
|
||||
|
||||
void WizardExtension::addWidget(QWidget *widget)
|
||||
{
|
||||
myWidget->addPage(widget);
|
||||
}
|
||||
|
||||
int WizardExtension::count() const
|
||||
{
|
||||
return myWidget->count();
|
||||
}
|
||||
|
||||
int WizardExtension::currentIndex() const
|
||||
{
|
||||
return myWidget->currentIndex();
|
||||
}
|
||||
|
||||
void WizardExtension::insertWidget(int index, QWidget *widget)
|
||||
{
|
||||
myWidget->insertPage(index, widget);
|
||||
}
|
||||
|
||||
void WizardExtension::remove(int index)
|
||||
{
|
||||
myWidget->removePage(index);
|
||||
}
|
||||
|
||||
void WizardExtension::setCurrentIndex(int index)
|
||||
{
|
||||
myWidget->setCurrentIndex(index);
|
||||
}
|
||||
|
||||
QWidget* WizardExtension::widget(int index) const
|
||||
{
|
||||
return myWidget->widget(index);
|
||||
}
|
||||
|
||||
WizardExtensionFactory::WizardExtensionFactory(QExtensionManager *parent)
|
||||
: QExtensionFactory(parent)
|
||||
{}
|
||||
|
||||
QObject *WizardExtensionFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
|
||||
{
|
||||
Wizard *widget = qobject_cast<Wizard*>(object);
|
||||
|
||||
if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
|
||||
return new WizardExtension(widget, parent);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
119
src/Tools/plugins/widget/wizard.h
Normal file
119
src/Tools/plugins/widget/wizard.h
Normal file
@@ -0,0 +1,119 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2007 Werner Mayer <wmayer@users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef WIZARD_H
|
||||
#define WIZARD_H
|
||||
|
||||
|
||||
#include <QtDesigner/QDesignerContainerExtension>
|
||||
#include <QtDesigner/QExtensionFactory>
|
||||
#include <QDialog>
|
||||
|
||||
class QLabel;
|
||||
class QFrame;
|
||||
class QStackedWidget;
|
||||
class QPushButton;
|
||||
class QHBoxLayout;
|
||||
class QVBoxLayout;
|
||||
class QExtensionManager;
|
||||
|
||||
class Wizard : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex)
|
||||
Q_PROPERTY(QString pageTitle READ pageTitle WRITE setPageTitle STORED false)
|
||||
|
||||
public:
|
||||
Wizard(QWidget *parent = 0);
|
||||
|
||||
QSize sizeHint() const;
|
||||
|
||||
void addPage(QWidget *page);
|
||||
void removePage(int index);
|
||||
int count() const;
|
||||
int currentIndex() const;
|
||||
void insertPage(int index, QWidget *page);
|
||||
void setCurrentIndex(int index);
|
||||
QWidget *widget(int index);
|
||||
|
||||
QPushButton* backButton() const;
|
||||
QPushButton* nextButton() const;
|
||||
|
||||
QString pageTitle() const;
|
||||
void setPageTitle(QString const &newTitle);
|
||||
|
||||
public Q_SLOTS:
|
||||
void backButtonClicked();
|
||||
void nextButtonClicked();
|
||||
|
||||
Q_SIGNALS:
|
||||
void currentIndexChanged(int index);
|
||||
void pageTitleChanged(const QString &title);
|
||||
|
||||
private:
|
||||
QLabel *textLabel;
|
||||
QFrame* topLine;
|
||||
QFrame* bottomLine;
|
||||
QStackedWidget *stackWidget;
|
||||
QPushButton *_cancelButton;
|
||||
QPushButton *_backButton;
|
||||
QPushButton *_nextButton;
|
||||
QPushButton *_finishButton;
|
||||
QHBoxLayout *buttonLayout;
|
||||
QVBoxLayout *mainLayout;
|
||||
};
|
||||
|
||||
class WizardExtension : public QObject, public QDesignerContainerExtension
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QDesignerContainerExtension)
|
||||
|
||||
public:
|
||||
WizardExtension(Wizard *widget, QObject *parent);
|
||||
|
||||
int count() const;
|
||||
QWidget *widget(int index) const;
|
||||
int currentIndex() const;
|
||||
void setCurrentIndex(int index);
|
||||
void addWidget(QWidget *widget);
|
||||
void insertWidget(int index, QWidget *widget);
|
||||
void remove(int index);
|
||||
|
||||
private:
|
||||
Wizard *myWidget;
|
||||
};
|
||||
|
||||
class QExtensionManager;
|
||||
|
||||
class WizardExtensionFactory : public QExtensionFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
WizardExtensionFactory(QExtensionManager *parent = 0);
|
||||
|
||||
protected:
|
||||
QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user