Commit 9a9588e9 authored by Boudewijn Rempt's avatar Boudewijn Rempt

* Remove obsolute method in paintop factory api (after one day! a record!)

* add a popup menu
* some more work on the paintop gui
* update HACKING

svn path=/trunk/koffice/; revision=498029
parent 3d0b58ef
......@@ -84,8 +84,10 @@ Files and classes
Spaces
Keep the source airy and open: put spaces around -> and * and the like.
Keep the source airy and open. (However, maybe I was wrong in wanting spaces around ->...)
Slots and signals
Prefix slots with slot and signals with sig: slotSelectionUpdated, sigSelectionUpdated.
Boudewijn Rempt
\ No newline at end of file
......@@ -37,11 +37,11 @@ public:
virtual KisPaintOp * createOp(KisPainter * painter);
virtual KisID id() { return KisID("wetbrush", i18n("Watercolor Brush")); }
virtual bool userVisible(KisColorSpace* cs) { return cs -> id() == KisID("WET", ""); }
virtual QWidget* createOptionWidget(QWidget* parent) {
m_optWidget = new WetPaintOptions();
virtual QWidget* optionWidget(QWidget* parent) {
if (!m_optWidget)
m_optWidget = new WetPaintOptions();
return m_optWidget;
}
virtual QWidget* optionWidget() { return m_optWidget; }
};
class KisWetOp : public KisPaintOp {
......
......@@ -358,8 +358,8 @@ public:
KisSelectionSP setSelection(KisSelectionSP selection);
signals:
void positionChanged(KisPaintDeviceImplSP device);
void ioProgress(Q_INT8 percentage);
void positionChanged(KisPaintDeviceImplSP device);
void ioProgress(Q_INT8 percentage);
void profileChanged(KisProfile * profile);
private:
......
......@@ -106,6 +106,5 @@ void KisPaintOp::setSource(KisPaintDeviceImplSP p) {
}
QWidget* KisPaintOpFactory::createOptionWidget(QWidget* parent) { return 0; }
QWidget* KisPaintOpFactory::optionWidget() { return 0; }
QWidget* KisPaintOpFactory::optionWidget(QWidget* parent) { return 0; }
......@@ -120,12 +120,7 @@ public:
/**
* Create and return a widget with options for this paintop.
*/
virtual QWidget* createOptionWidget(QWidget* parent);
/**
* @return the earlier-created option widget
*/
virtual QWidget* optionWidget();
virtual QWidget* optionWidget(QWidget* parent);
};
#endif // KIS_PAINTOP_H_
......@@ -16,6 +16,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <qpixmap.h>
#include <qwidget.h>
#include <kdebug.h>
#include <kinstance.h>
......@@ -81,7 +82,7 @@ KisPaintOp * KisPaintOpRegistry::paintOp(const KisID & id, KisPainter * painter)
return 0;
}
KisPaintOpFactorySP f = get(id);
if (f) {
if (f) {
return f -> createOp(painter);
}
else {
......@@ -94,6 +95,12 @@ KisPaintOp * KisPaintOpRegistry::paintOp(const QString & id, KisPainter * painte
return paintOp(KisID(id, ""), painter);
}
QWidget * KisPaintOpRegistry::configWidget(const KisID& id, QWidget * parent) const
{
KisPaintOpFactory* f = get(id);
return f->optionWidget( parent );
}
bool KisPaintOpRegistry::userVisible(const KisID & id, KisColorSpace* cs) const
{
......
......@@ -25,7 +25,9 @@
#include "kis_generic_registry.h"
#include <koffice_export.h>
class QWidget;
class QStringList;
class KisPaintOp;
class KisPainter;
class KisColorSpace;
......@@ -38,9 +40,23 @@ class KRITACORE_EXPORT KisPaintOpRegistry : public QObject, public KisGenericReg
public:
virtual ~KisPaintOpRegistry();
/**
* Return a newly created paintop
*/
KisPaintOp * paintOp(const KisID& id, KisPainter * painter) const;
/**
* Return a newly created paintopd
*/
KisPaintOp * paintOp(const QString& id, KisPainter * painter) const;
/**
* Return or create and return a configuration widhget
* for the specified paintop with the specified parent
* as widget parent.
*/
QWidget * configWidget(const KisID& id, QWidget * parent) const;
// Whether we should show this paintop in the toolchest
bool userVisible(const KisID & id, KisColorSpace* cs) const;
......
......@@ -170,6 +170,21 @@
<Action name="patterns"/>
<Separator/>
<Action name="paintops"/>
<Action name="paintop_options"/>
</ToolBar>
<Menu name="image_popup">
<Action name="select_all"/>
<Action name="deselect"/>
<Action name="invert"/>
<Separator/>
<Action name="koffice_undo"/>
<Action name="koffice_redo"/>
<Separator/>
<Action name="cut"/>
<Action name="copy"/>
<Action name="paste"/>
<Action name="paste_new"/>
</Menu>
</kpartgui>
......@@ -25,10 +25,12 @@
#include "kis_paintop.h"
#include "qlabel.h"
#include <qwidget.h>
class KisPoint;
class KisPainter;
class KisBrushOpFactory : public KisPaintOpFactory {
public:
......@@ -38,7 +40,7 @@ public:
virtual KisPaintOp * createOp(KisPainter * painter);
virtual KisID id() { return KisID("paintbrush", i18n("Pixel Brush")); }
virtual QString pixmap() { return "paintbrush.png"; }
//virtual QWidget * optionWidget(QWidget * parent) { return new QLabel("brushop", parent); }
};
class KisBrushOp : public KisPaintOp {
......
......@@ -23,6 +23,8 @@
#ifndef KIS_PENOP_H_
#define KIS_PENOP_H_
#include <qlabel.h>
#include <qwidget.h>
#include "kis_paintop.h"
class KisPoint;
......@@ -37,6 +39,7 @@ public:
virtual KisPaintOp * createOp(KisPainter * painter);
virtual KisID id(){ return KisID("pen", i18n("Pixel Pencil")); }
virtual QString pixmap() { return "pencil.png"; }
//virtual QWidget * optionWidget(QWidget * parent) { return new QLabel("penop", parent); }
};
......
......@@ -88,6 +88,7 @@ void KisToolBrush::initPaint(KisEvent *e)
return;
}
KisPaintOp * op = KisPaintOpRegistry::instance()->paintOp(m_subject->currentPaintop(), m_painter);
kdDebug() << "Paintop : " << op << "\n";
if (!op) return;
m_subject -> canvasController() -> kiscanvas() -> update(); // remove the outline
......
......@@ -60,7 +60,8 @@ void KisToolDuplicate::activate()
void KisToolDuplicate::buttonPress(KisButtonPressEvent *e)
{
if (e -> button() == RightButton) {
if (e->state() == ShiftButton) {
kdDebug() << "Shift button pressed, going to set htis place for duplicate\n";
m_position = e->pos();
m_isOffsetNotUptodate = true;
} else {
......@@ -150,7 +151,7 @@ void KisToolDuplicate::paintAt(const KisPoint &pos,
}
QString KisToolDuplicate::quickHelp() const {
return i18n("To start, right click on the place you want to duplicate from. Then you can start painting. An indication of where you are copying from will be displayed while drawing and moving the mouse.");
return i18n("To start, shift-click on the place you want to duplicate from. Then you can start painting. An indication of where you are copying from will be displayed while drawing and moving the mouse.");
}
#include "kis_tool_duplicate.moc"
......@@ -24,10 +24,19 @@ class KisButtonEvent : public KisEvent {
typedef KisEvent super;
public:
Qt::ButtonState button() const { return m_button; }
protected:
KisButtonEvent() {}
KisButtonEvent(enumEventType type, enumInputDevice device, const KisPoint& pos, const KisPoint& globalPos, double pressure, double xTilt, double yTilt, Qt::ButtonState button, Qt::ButtonState state) : super(type, device, pos, globalPos, pressure, xTilt, yTilt, state), m_button(button) {}
KisButtonEvent(enumEventType type,
enumInputDevice device,
const KisPoint& pos,
const KisPoint& globalPos,
double pressure,
double xTilt, double yTilt,
Qt::ButtonState button,
Qt::ButtonState state)
: super(type, device, pos, globalPos, pressure, xTilt, yTilt, state)
, m_button(button) {}
Qt::ButtonState m_button;
};
......
......@@ -21,8 +21,10 @@
#include <qstring.h>
#include <qvaluelist.h>
#include <qpixmap.h>
#include <qlayout.h>
#include <klocale.h>
#include <kactioncollection.h>
#include <kis_id.h>
#include <kis_paintop_registry.h>
......@@ -38,11 +40,16 @@ KisPaintopBox::KisPaintopBox (KisView * view, QWidget *parent, const char * name
m_view(view)
{
setCaption(i18n("Painter's Toolchest"));
m_optionWidget = 0;
m_paintops = new QValueList<KisID>();
m_displayedOps = new QValueList<KisID>();
m_cmbPaintops = new QComboBox(this, "KisPaintopBox::m_cmbPaintops");
m_layout = new QHBoxLayout(this, 1, 1);
m_layout->addWidget(m_cmbPaintops);
connect(this, SIGNAL(selected(const KisID &)), m_view, SLOT(paintopActivated(const KisID &)));
connect(this, SIGNAL(highlighted(int)), this, SLOT(slotItemSelected(int)));
connect(m_cmbPaintops, SIGNAL(highlighted(int)), this, SLOT(slotItemSelected(int)));
// XXX: Let's see... Are all paintops loaded and ready?
KisIDList keys = KisPaintOpRegistry::instance()->listKeys();
......@@ -71,6 +78,15 @@ void KisPaintopBox::addItem(const KisID & paintop, const QString & /*category*/)
void KisPaintopBox::slotItemSelected(int index)
{
KisID id = *m_paintops->at(index);
if (m_optionWidget != 0) {
m_layout->remove(m_optionWidget);
}
QWidget * m_optionWidget = KisPaintOpRegistry::instance()->configWidget( id, this );
if (m_optionWidget != 0) {
m_layout->addWidget(m_optionWidget);
}
m_currentID = id;
emit selected(id);
}
......@@ -80,7 +96,7 @@ void KisPaintopBox::colorSpaceChanged(KisColorSpace *cs)
QValueList<KisID>::iterator it = m_paintops -> begin();
QValueList<KisID>::iterator end = m_paintops -> end();
m_displayedOps -> clear();
clear();
m_cmbPaintops->clear();
for ( ; it != end; ++it ) {
if (KisPaintOpRegistry::instance() -> userVisible(*it, cs)) {
......@@ -89,16 +105,16 @@ void KisPaintopBox::colorSpaceChanged(KisColorSpace *cs)
if (pm.isNull()) {
QPixmap p = QPixmap( 16, 16 );
p.fill();
insertItem(p, (*it).name());
m_cmbPaintops->insertItem(p, (*it).name());
}
else {
insertItem(pm, (*it).name());
m_cmbPaintops->insertItem(pm, (*it).name());
}
m_displayedOps -> append(*it);
}
}
setCurrentItem( m_displayedOps -> findIndex ( m_currentID ) );
m_cmbPaintops->setCurrentItem( m_displayedOps->findIndex ( m_currentID ) );
}
#include "kis_paintop_box.moc"
......@@ -21,9 +21,11 @@
#ifndef KIS_PAINTOP_BOX_H_
#define KIS_PAINTOP_BOX_H_
#include <qwidget.h>
#include <qcombobox.h>
#include <qvaluelist.h>
class KWidgetAction;
class KisView;
class KisID;
class QString;
......@@ -39,11 +41,11 @@ class KisColorSpace;
*
* XXX: instead of text, use pretty pictures.
*/
class KisPaintopBox : public QComboBox {
class KisPaintopBox : public QWidget {
Q_OBJECT
typedef QComboBox super;
typedef QWidget super;
public:
KisPaintopBox (KisView * view, QWidget * parent, const char * name = 0);
......@@ -65,10 +67,15 @@ private slots:
private:
KisView * m_view;
QComboBox * m_cmbPaintops;
QHBoxLayout * m_layout;
QWidget * m_optionWidget;
QValueList<KisID> * m_paintops;
QValueList<KisID> * m_displayedOps;
KisID m_currentID;
};
......
......@@ -26,7 +26,6 @@
#include "kis_point.h"
#include "koffice_export.h"
class QWidget;
class KisPainter;
class KisBrush;
class KisEvent;
......
......@@ -140,8 +140,6 @@ QWidget* KisToolPaint::createOptionWidget(QWidget* parent)
m_optionWidgetLayout -> addWidget(m_lbComposite, 1, 0);
m_optionWidgetLayout -> addMultiCellWidget(m_cmbComposite, 1, 1, 1, 2);
m_optionWidgetLayout -> addWidget(m_chkDirect, 2, 0);
// XXX make this a picture of a '?', like you see everywhere
QPushButton* push = new QPushButton("?", m_optionWidget);
......
......@@ -160,6 +160,7 @@ KisView::KisView(KisDoc *doc, KisUndoAdapter *adapter, QWidget *parent, const ch
, KXMLGUIBuilder( shell() )
, m_doc( doc )
, m_canvas( 0 )
, m_popup( 0 )
, m_selectionManager( 0 )
, m_filterManager( 0 )
, m_paletteManager( 0 )
......@@ -599,7 +600,6 @@ void KisView::setupActions()
m_RulerAction = new KToggleAction( i18n( "Show Rulers" ), "Ctrl+R", this, SLOT( showRuler() ), actionCollection(), "view_ruler" );
m_RulerAction->setChecked(cfg.showRulers());
m_RulerAction->setCheckedState(i18n("Hide Rulers"));
m_RulerAction->setToolTip( i18n( "Shows or hides rulers." ) );
m_RulerAction->setWhatsThis( i18n("The rulers show the horizontal and vertical positions of the mouse on the image "
"and can be used to position your mouse at the right place on the canvas. <p>Uncheck this to disable "
"the rulers from being displayed." ) );
......@@ -1892,6 +1892,7 @@ void KisView::gradientActivated(KisResource *gradient)
void KisView::paintopActivated(const KisID & paintop)
{
kdDebug() << "paintop activated: " << paintop.id() << "\n";
if (paintop.id().isNull() || paintop.id().isEmpty()) {
return;
......@@ -2051,8 +2052,15 @@ void KisView::canvasGotButtonPressEvent(KisButtonPressEvent *e)
// }
// }
// }
if (e->button() == Qt::RightButton) {
if (e -> device() == currentInputDevice() && m_toolManager->currentTool()) {
if (m_popup == 0) {
Q_ASSERT(factory());
m_popup = (QPopupMenu *)factory()->container("image_popup", this);
}
m_popup->popup(e->globalPos().roundQPoint());
}
else if (e -> device() == currentInputDevice() && m_toolManager->currentTool()) {
KisPoint p = viewToWindow(e -> pos());
// somewhat of a hack: we should actually test if we intersect with the scrollers,
// but the globalPos seems to be off by a few pixels
......
......@@ -54,6 +54,7 @@ class QLabel;
class QPaintEvent;
class QScrollBar;
class QWidget;
class QPopup;
class DCOPObject;
class KAction;
......@@ -454,7 +455,8 @@ private:
KisDoc *m_doc;
KisCanvas *m_canvas;
QPopupMenu * m_popup;
KisSelectionManager * m_selectionManager;
KisFilterManager * m_filterManager;
KoPaletteManager * m_paletteManager;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment