Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 18798 → Rev 18799

/trunk/Scribus/scribus/CMakeLists.txt
138,7 → 138,7
ui/propertiespalette_groupbase.ui
ui/propertiespalette_imagebase.ui
ui/propertiespalette_linebase.ui
ui/propertiespalette_shadowbase.ui
# ui/propertiespalette_shadowbase.ui
ui/propertiespalette_shapebase.ui
ui/propertiespalette_tablebase.ui
ui/propertiespalette_textbase.ui
419,6 → 419,7
ui/propertywidget_orphans.h
ui/propertywidget_pathtext.h
ui/propertywidget_textcolor.h
ui/proptree.h
ui/query.h
ui/replacecolors.h
ui/replaceonecolor.h
867,6 → 868,7
ui/propertywidget_pathtext.cpp
ui/propertywidget_textcolor.cpp
ui/propertywidgetbase.cpp
ui/proptree.cpp
ui/query.cpp
ui/replacecolors.cpp
ui/replaceonecolor.cpp
/trunk/Scribus/scribus/ui/propertiespalette_shadow.cpp
15,7 → 15,6
#include "sccolorengine.h"
#include "pageitem.h"
#include "propertiespalette_utils.h"
#include "sccombobox.h"
#include "scribus.h"
#include "scribuscore.h"
#include "scraction.h"
27,6 → 26,446
#include "util_icon.h"
#include "util_math.h"
 
PropertiesPalette_Shadow::PropertiesPalette_Shadow( QWidget* parent) : PropTreeWidget(parent)
{
m_ScMW = 0;
m_doc = 0;
m_haveDoc = false;
m_haveItem = false;
m_unitRatio = 1.0;
hasSoftShadow = new PropTreeItem(this, PropTreeItem::CheckBox, tr( "Has Drop Shadow"));
hasSoftShadow->setBoolValue(false);
 
softShadowXOffset = new PropTreeItem(this, PropTreeItem::DoubleSpinBox, tr( "X-Offset:"));
softShadowXOffset->setUnitValue(0);
softShadowXOffset->setDecimalsValue(2);
softShadowXOffset->setMinMaxValues(-200.0, 200.0);
softShadowXOffset->setDoubleValue(5.0);
 
softShadowYOffset = new PropTreeItem(this, PropTreeItem::DoubleSpinBox, tr( "Y-Offset:"));
softShadowYOffset->setUnitValue(0);
softShadowYOffset->setDecimalsValue(2);
softShadowYOffset->setMinMaxValues(-200.0, 200.0);
softShadowYOffset->setDoubleValue(5.0);
 
softShadowBlurRadius = new PropTreeItem(this, PropTreeItem::DoubleSpinBox, tr( "Blur:"));
softShadowBlurRadius->setUnitValue(0);
softShadowBlurRadius->setDecimalsValue(1);
softShadowBlurRadius->setMinMaxValues(-20.0, 20.0);
softShadowBlurRadius->setDoubleValue(2.0);
 
softShadowColor = new PropTreeItem(this, PropTreeItem::ColorCombo, tr( "Color:"));
softShadowColor->setStringValue( tr( "Black"));
 
softShadowShade = new PropTreeItem(this, PropTreeItem::IntSpinBox, tr( "Shade:"));
softShadowShade->setUnitValue(7);
softShadowShade->setDecimalsValue(0);
softShadowShade->setMinMaxValues(0, 100);
softShadowShade->setIntValue(100);
 
softShadowOpacity = new PropTreeItem(this, PropTreeItem::DoubleSpinBox, tr( "Opacity:"));
softShadowOpacity->setUnitValue(7);
softShadowOpacity->setDecimalsValue(1);
softShadowOpacity->setMinMaxValues(0.0, 100.0);
softShadowOpacity->setDoubleValue(100.0);
 
softShadowBlendMode = new PropTreeItem(this, PropTreeItem::ComboBox, tr( "Blendmode:"));
QStringList modes;
softShadowBlendMode->setComboStrings(modes);
softShadowBlendMode->setStringValue( tr( "Normal"));
 
languageChange();
m_haveItem = false;
setSizePolicy( QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
connect(hasSoftShadow, SIGNAL(valueChanged(bool)), this, SLOT(handleShadow(bool)));
connect(softShadowXOffset, SIGNAL(valueChanged(double)), this, SLOT(handleNewXOffset(double)));
connect(softShadowYOffset, SIGNAL(valueChanged(double)), this, SLOT(handleNewYOffset(double)));
connect(softShadowBlurRadius, SIGNAL(valueChanged(double)), this, SLOT(handleNewBlur(double)));
connect(softShadowColor, SIGNAL(valueChanged(QString)), this, SLOT(handleNewColor(QString)));
connect(softShadowShade, SIGNAL(valueChanged(double)), this, SLOT(handleNewShade(double)));
connect(softShadowOpacity, SIGNAL(valueChanged(double)), this, SLOT(handleNewOpacity(double)));
connect(softShadowBlendMode, SIGNAL(valueChanged(int)), this, SLOT(handleNewBlendmode(int)));
 
m_haveItem = false;
}
 
void PropertiesPalette_Shadow::setMainWindow(ScribusMainWindow* mw)
{
m_ScMW = mw;
connect(m_ScMW, SIGNAL(UpdateRequest(int)), this, SLOT(handleUpdateRequest(int)));
}
 
void PropertiesPalette_Shadow::setDoc(ScribusDoc *d)
{
if((d == (ScribusDoc*) m_doc) || (m_ScMW && m_ScMW->scriptIsRunning()))
return;
 
if (m_doc)
{
disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
disconnect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
}
 
m_doc = d;
m_item = NULL;
m_unitRatio = m_doc->unitRatio();
m_unitIndex = m_doc->unitIndex();
int precision = unitGetPrecisionFromIndex(m_unitIndex);
double maxXYWHVal = 200 * m_unitRatio;
double minXYVal = -200 * m_unitRatio;
 
m_haveDoc = true;
m_haveItem = false;
softShadowXOffset->setUnitValue(m_unitIndex);
softShadowXOffset->setDecimalsValue(precision);
softShadowXOffset->setMinMaxValues(minXYVal, maxXYWHVal);
softShadowXOffset->setDoubleValue(minXYVal);
 
softShadowYOffset->setUnitValue(m_unitIndex);
softShadowYOffset->setDecimalsValue(precision);
softShadowYOffset->setMinMaxValues(minXYVal, maxXYWHVal);
softShadowYOffset->setDoubleValue(minXYVal);
 
softShadowBlurRadius->setUnitValue(m_unitIndex);
softShadowBlurRadius->setDecimalsValue(1);
softShadowBlurRadius->setMinMaxValues(0.0, 20.0);
softShadowBlurRadius->setDoubleValue(5);
 
softShadowShade->setDecimalsValue(0);
softShadowShade->setMinMaxValues(0, 100);
softShadowShade->setIntValue(100);
 
softShadowOpacity->setDecimalsValue(0);
softShadowOpacity->setMinMaxValues(0, 100);
softShadowOpacity->setIntValue(100);
updateColorList();
 
connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
connect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
}
 
void PropertiesPalette_Shadow::unsetDoc()
{
if (m_doc)
{
disconnect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
disconnect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
}
m_haveDoc = false;
m_haveItem = false;
m_doc = NULL;
m_item = NULL;
setEnabled(false);
}
 
void PropertiesPalette_Shadow::unsetItem()
{
m_haveItem = false;
m_item = NULL;
handleSelectionChanged();
}
 
void PropertiesPalette_Shadow::handleUpdateRequest(int updateFlags)
{
if (updateFlags & reqColorsUpdate)
updateColorList();
}
 
PageItem* PropertiesPalette_Shadow::currentItemFromSelection()
{
PageItem *currentItem = NULL;
if (m_doc)
{
if (m_doc->m_Selection->count() > 1)
currentItem = m_doc->m_Selection->itemAt(0);
else if (m_doc->m_Selection->count() == 1)
currentItem = m_doc->m_Selection->itemAt(0);
}
return currentItem;
}
 
void PropertiesPalette_Shadow::setCurrentItem(PageItem *i)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
if (!m_doc)
setDoc(i->doc());
m_haveItem = false;
m_item = i;
hasSoftShadow->setBoolValue(i->hasSoftShadow());
softShadowXOffset->setDoubleValue(i->softShadowXOffset() * m_unitRatio);
softShadowYOffset->setDoubleValue(i->softShadowYOffset() * m_unitRatio);
softShadowBlurRadius->setDoubleValue(i->softShadowBlurRadius() * m_unitRatio);
softShadowColor->setStringValue(i->softShadowColor());
softShadowShade->setIntValue(i->softShadowShade());
softShadowOpacity->setDoubleValue(qRound(100 - (i->softShadowOpacity() * 100)));
softShadowBlendMode->setIntValue(i->softShadowBlendMode());
m_haveItem = true;
updateSpinBoxConstants();
}
 
void PropertiesPalette_Shadow::handleSelectionChanged()
{
if (!m_haveDoc || !m_ScMW || m_ScMW->scriptIsRunning())
return;
 
PageItem* currItem = currentItemFromSelection();
if (currItem)
setCurrentItem(currItem);
updateGeometry();
}
 
void PropertiesPalette_Shadow::unitChange()
{
if (!m_haveDoc)
return;
m_unitRatio = m_doc->unitRatio();
m_unitIndex = m_doc->unitIndex();
softShadowXOffset->setUnitValue(m_unitIndex);
softShadowYOffset->setUnitValue(m_unitIndex);
softShadowBlurRadius->setUnitValue(m_unitIndex);
}
 
void PropertiesPalette_Shadow::updateColorList()
{
if (!m_haveDoc || !m_ScMW || m_ScMW->scriptIsRunning())
return;
softShadowColor->setColorList(m_doc->PageColors);
}
 
void PropertiesPalette_Shadow::handleNewValues()
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleShadow(bool value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(value, color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewXOffset(double value)
{
if (m_haveItem)
{
double x = value / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsInt()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewYOffset(double value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = value / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsInt()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewBlur(double value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = value / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewColor(QString value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = value;
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewShade(double value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = qRound(value);
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewOpacity(double value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = softShadowBlendMode->valueAsInt();
double o = (100 - value) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::handleNewBlendmode(int value)
{
if (m_haveItem)
{
double x = softShadowXOffset->valueAsDouble() / m_unitRatio;
double y = softShadowYOffset->valueAsDouble() / m_unitRatio;
double r = softShadowBlurRadius->valueAsDouble() / m_unitRatio;
QString color = softShadowColor->valueAsString();
if (color == CommonStrings::tr_NoneColor)
color = CommonStrings::None;
int b = value;
double o = (100 - softShadowOpacity->valueAsDouble()) / 100.0;
int s = softShadowShade->valueAsInt();
if (m_haveDoc)
{
m_doc->itemSelection_SetSoftShadow(hasSoftShadow->valueAsBool(), color, x, y, r, s, o, b);
}
}
}
 
void PropertiesPalette_Shadow::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange)
{
languageChange();
}
else
QWidget::changeEvent(e);
}
 
void PropertiesPalette_Shadow::languageChange()
{
hasSoftShadow->setText(0, tr( "Has Drop Shadow"));
softShadowXOffset->setText(0, tr( "X-Offset:"));
softShadowYOffset->setText(0, tr( "Y-Offset:"));
softShadowBlurRadius->setText(0, tr( "Blur:"));
softShadowColor->setText(0, tr( "Color:"));
softShadowShade->setText(0, tr( "Shade:"));
softShadowOpacity->setText(0, tr( "Opacity:"));
QStringList modes;
modes.append( tr("Normal"));
modes.append( tr("Darken"));
modes.append( tr("Lighten"));
modes.append( tr("Multiply"));
modes.append( tr("Screen"));
modes.append( tr("Overlay"));
modes.append( tr("Hard Light"));
modes.append( tr("Soft Light"));
modes.append( tr("Difference"));
modes.append( tr("Exclusion"));
modes.append( tr("Color Dodge"));
modes.append( tr("Color Burn"));
modes.append( tr("Hue"));
modes.append( tr("Saturation"));
modes.append( tr("Color"));
modes.append( tr("Luminosity"));
softShadowBlendMode->setComboStrings(modes);
softShadowBlendMode->setStringValue( tr("Normal"));
softShadowBlendMode->setText(0, tr( "Blendmode:"));
}
 
void PropertiesPalette_Shadow::updateSpinBoxConstants()
{
if (!m_haveDoc)
return;
if(m_doc->m_Selection->count()==0)
return;
// softShadowXOffset->setConstants(&m_doc->constants());
// softShadowYOffset->setConstants(&m_doc->constants());
 
}
 
/*
PropertiesPalette_Shadow::PropertiesPalette_Shadow( QWidget* parent) : QWidget(parent)
{
m_ScMW = 0;
34,10 → 473,8
m_haveDoc = false;
m_haveItem = false;
m_unitRatio = 1.0;
 
setupUi(this);
setSizePolicy( QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum));
 
_userActionOn = false;
userActionSniffer = new UserActionSniffer(this);
connect(userActionSniffer, SIGNAL(actionStart()), this, SLOT(spinboxStartUserAction()));
321,5 → 758,5
return;
softShadowXOffset->setConstants(&m_doc->constants());
softShadowYOffset->setConstants(&m_doc->constants());
 
}
*/
/trunk/Scribus/scribus/ui/propertiespalette_shadow.h
7,6 → 7,80
#ifndef PROPERTIESPALETTE_SHADOW_H
#define PROPERTIESPALETTE_SHADOW_H
 
#include "scribusapi.h"
#include "scguardedptr.h"
 
#include "proptree.h"
#include <QVBoxLayout>
 
class PageItem;
class ScribusDoc;
class Selection;
class ScribusMainWindow;
 
class SCRIBUS_API PropertiesPalette_Shadow : public PropTreeWidget
{
Q_OBJECT
 
public:
PropertiesPalette_Shadow(QWidget* parent);
~PropertiesPalette_Shadow() {};
 
virtual void changeEvent(QEvent *e);
void updateColorList();
 
private:
 
PageItem* currentItemFromSelection();
 
public slots:
void setMainWindow(ScribusMainWindow *mw);
 
void setDoc(ScribusDoc *d);
void setCurrentItem(PageItem *i);
void unsetDoc();
void unsetItem();
 
void languageChange();
void unitChange();
void handleSelectionChanged();
void handleUpdateRequest(int);
 
private slots:
void handleNewValues();
void handleShadow(bool value);
void handleNewXOffset(double value);
void handleNewYOffset(double value);
void handleNewBlur(double value);
void handleNewColor(QString value);
void handleNewShade(double value);
void handleNewOpacity(double value);
void handleNewBlendmode(int value);
 
protected slots:
void updateSpinBoxConstants();
 
protected:
PropTreeItem *hasSoftShadow;
PropTreeItem *softShadowXOffset;
PropTreeItem *softShadowYOffset;
PropTreeItem *softShadowBlurRadius;
PropTreeItem *colorProps;
PropTreeItem *softShadowColor;
PropTreeItem *softShadowShade;
PropTreeItem *softShadowOpacity;
PropTreeItem *softShadowBlendMode;
ScribusMainWindow *m_ScMW;
 
bool m_haveDoc;
bool m_haveItem;
double m_unitRatio;
int m_unitIndex;
PageItem *m_item;
ScGuardedPtr<ScribusDoc> m_doc;
};
 
/*
#include "ui_propertiespalette_shadowbase.h"
 
#include "scribusapi.h"
30,7 → 104,7
 
virtual void changeEvent(QEvent *e);
 
/** @brief Returns true if there is a user action going on at the moment of call. */
// @brief Returns true if there is a user action going on at the moment of call.
bool userActionOn(); // not yet implemented!!! This is needed badly.
// When user releases the mouse button or arrow key, changes must be checked
// and if in ScribusView a groupTransaction has been started it must be also
76,5 → 150,5
UserActionSniffer *userActionSniffer;
void installSniffer(ScrSpinBox *spinBox);
};
 
*/
#endif
/trunk/Scribus/scribus/ui/proptree.cpp
0,0 → 1,462
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
proptree.cpp - description
-------------------
begin : Mon Feb 3 2014
copyright : (C) 2008 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
 
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
 
#include <QAbstractItemModel>
#include <QStyle>
#include <QPainter>
#include <QHeaderView>
#include <QLayout>
 
#include "proptree.h"
 
#include "colorcombo.h"
#include "scrspinbox.h"
#include "sccombobox.h"
#include <QCheckBox>
#include <QApplication>
#include "units.h"
#include "util.h"
 
PropTreeItemDelegate::PropTreeItemDelegate(PropTreeWidget *parent) : QItemDelegate(parent)
{
m_parent = parent;
}
 
void PropTreeItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItem itemOpts = option;
itemOpts.state &= ~QStyle::State_HasFocus;
PropTreeItem* item = (PropTreeItem*)m_parent->indexToItem(index);
if ((index.column() == 1) && (item->m_type == PropTreeItem::CheckBox) && !(option.state & QStyle::State_Editing))
{
QStyleOptionButton buttonOption;
buttonOption.rect = option.rect;
buttonOption.palette = option.palette;
if (index.model()->data(index, Qt::UserRole).toBool())
buttonOption.state |= QStyle::State_On;
else
buttonOption.state |= QStyle::State_Off;
QApplication::style()->drawControl(QStyle::CE_CheckBox, &buttonOption, painter);
}
else if (index.column() == 0)
{
int i = 9; // ### hardcoded in qcommonstyle.cpp
QRect r = option.rect;
if (item && (item->childCount() > 0))
{
painter->save();
if (option.state & QStyle::State_Enabled)
painter->setBrush(Qt::black);
else
painter->setBrush(Qt::gray);
painter->setPen(Qt::NoPen);
QRect rect = QRect(r.left()+6, r.top()+6, r.height()-12, r.height()-12);
QPolygon pa(3);
if (item->isExpanded())
{
pa.setPoint(0, rect.left(), rect.top());
pa.setPoint(1, rect.right(), rect.top());
pa.setPoint(2, rect.center().x(), rect.bottom());
}
else
{
pa.setPoint(0, rect.left(), rect.top());
pa.setPoint(1, rect.left(), rect.bottom());
pa.setPoint(2, rect.right(), rect.center().y());
}
painter->setRenderHint(QPainter::Antialiasing, true);
painter->drawPolygon(pa);
painter->restore();
}
painter->save();
if (item && (item->QTreeWidgetItem::parent()))
i = 15;
if (item && (item->treeWidget()->currentItem() == item))
{
itemOpts.font.setBold(true);
painter->setFont(itemOpts.font);
}
QRect textrect = QRect(r.left() + i*2, r.top(), r.width() - (i * 2), r.height());
QString text = itemOpts.fontMetrics.elidedText(index.model()->data(index, Qt::DisplayRole).toString(), Qt::ElideMiddle, itemOpts.rect.width(), Qt::TextShowMnemonic);
QApplication::style()->drawItemText(painter, textrect, Qt::AlignVCenter | Qt::AlignLeft | Qt::TextShowMnemonic, itemOpts.palette, (itemOpts.state & QStyle::State_Enabled), text, QPalette::Text);
painter->restore();
}
else
QItemDelegate::paint(painter, itemOpts, index);
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option));
painter->save();
painter->setPen(QPen(color));
painter->drawLine(option.rect.x(), option.rect.top(), option.rect.x(), option.rect.bottom());
painter->restore();
}
 
QWidget *PropTreeItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */, const QModelIndex &index) const
{
QWidget *edito = NULL;
PropTreeItem* item = (PropTreeItem*)m_parent->indexToItem(index);
if (item->m_type == PropTreeItem::IntSpinBox)
{
ScrSpinBox *editor = new ScrSpinBox(parent, item->m_unit);
int val = index.model()->data(index, Qt::UserRole).toInt();
editor->setValues(item->m_min, item->m_max, 0, val);
edito = editor;
edito->setAutoFillBackground(true);
connect(editor, SIGNAL(valueChanged(double)), item, SIGNAL(valueChanged(double)));
connect(editor, SIGNAL(valueChanged(double)), this, SLOT(valueHasChanged()));
}
else if (item->m_type == PropTreeItem::DoubleSpinBox)
{
ScrSpinBox *editor = new ScrSpinBox(parent, item->m_unit);
double val = index.model()->data(index, Qt::UserRole).toDouble();
editor->setValues(item->m_fmin, item->m_fmax, item->m_decimals, val);
edito = editor;
edito->setAutoFillBackground(true);
connect(editor, SIGNAL(valueChanged(double)), item, SIGNAL(valueChanged(double)));
connect(editor, SIGNAL(valueChanged(double)), this, SLOT(valueHasChanged()));
}
else if (item->m_type == PropTreeItem::ComboBox)
{
ScComboBox *editor = new ScComboBox(parent);
editor->addItems(index.model()->data(index, Qt::UserRole+1).toStringList());
edito = editor;
edito->setAutoFillBackground(true);
connect(editor, SIGNAL(activated(int)), item, SIGNAL(valueChanged(int)));
connect(editor, SIGNAL(activated(QString)), item, SIGNAL(valueChanged(QString)));
connect(editor, SIGNAL(activated(int)), this, SLOT(valueHasChanged()));
}
else if (item->m_type == PropTreeItem::CheckBox)
{
QCheckBox *editor = new QCheckBox(parent);
edito = editor;
edito->setAutoFillBackground(true);
connect(editor, SIGNAL(clicked(bool)), item, SIGNAL(valueChanged(bool)));
connect(editor, SIGNAL(clicked(bool)), this, SLOT(valueHasChanged()));
}
else if (item->m_type == PropTreeItem::ColorCombo)
{
ColorCombo *editor = new ColorCombo(parent);
editor->updateBox(item->m_colors, ColorCombo::fancyPixmaps, false);
edito = editor;
edito->setAutoFillBackground(true);
connect(editor, SIGNAL(activated(int)), item, SIGNAL(valueChanged(int)));
connect(editor, SIGNAL(activated(QString)), item, SIGNAL(valueChanged(QString)));
connect(editor, SIGNAL(activated(int)), this, SLOT(valueHasChanged()));
}
else
edito = 0;
m_edit = edito;
if (item)
emit item->editStarted();
return edito;
}
 
void PropTreeItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
{
PropTreeItem* item = (PropTreeItem*)m_parent->indexToItem(index);
if (item->m_type == PropTreeItem::IntSpinBox)
{
ScrSpinBox *spinBox = static_cast<ScrSpinBox*>(editor);
spinBox->setValue(index.model()->data(index, Qt::UserRole).toInt());
}
else if (item->m_type == PropTreeItem::DoubleSpinBox)
{
ScrSpinBox *spinBox = static_cast<ScrSpinBox*>(editor);
spinBox->setValue(index.model()->data(index, Qt::UserRole).toDouble());
}
else if (item->m_type == PropTreeItem::ComboBox)
{
ScComboBox *comboBox = static_cast<ScComboBox*>(editor);
setCurrentComboItem(comboBox ,index.model()->data(index, Qt::UserRole).toString());
}
else if (item->m_type == PropTreeItem::CheckBox)
{
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
checkBox->setChecked(index.model()->data(index, Qt::UserRole).toBool());
}
else if (item->m_type == PropTreeItem::ColorCombo)
{
ColorCombo *comboBox = static_cast<ColorCombo*>(editor);
setCurrentComboItem(comboBox ,index.model()->data(index, Qt::UserRole).toString());
}
}
 
void PropTreeItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
PropTreeItem* item = (PropTreeItem*)m_parent->indexToItem(index);
if (item->m_type == PropTreeItem::IntSpinBox)
{
ScrSpinBox *spinBox = static_cast<ScrSpinBox*>(editor);
QString value = QString("%1 %2").arg(qRound(spinBox->value())).arg(unitGetSuffixFromIndex(item->m_unit));
int val = qRound(spinBox->value());
model->setData(index, val, Qt::UserRole);
model->setData(index, value, Qt::DisplayRole);
}
else if (item->m_type == PropTreeItem::DoubleSpinBox)
{
ScrSpinBox *spinBox = static_cast<ScrSpinBox*>(editor);
QString value = QString("%1 %2").arg(spinBox->value(), 0, 'f', item->m_decimals).arg(unitGetSuffixFromIndex(item->m_unit));
double val = spinBox->value();
model->setData(index, val, Qt::UserRole);
model->setData(index, value, Qt::DisplayRole);
}
else if (item->m_type == PropTreeItem::ComboBox)
{
ScComboBox *comboBox = static_cast<ScComboBox*>(editor);
QString value = comboBox->currentText();
int val = comboBox->currentIndex();
item->m_comboIndex = val;
model->setData(index, value, Qt::UserRole);
model->setData(index, value, Qt::DisplayRole);
}
else if (item->m_type == PropTreeItem::CheckBox)
{
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
bool value = checkBox->isChecked();
model->setData(index, value, Qt::UserRole);
model->setData(index, value, Qt::DisplayRole);
}
else if (item->m_type == PropTreeItem::ColorCombo)
{
ColorCombo *comboBox = static_cast<ColorCombo*>(editor);
QString value = comboBox->currentText();
int val = comboBox->currentIndex();
item->m_comboIndex = val;
model->setData(index, value, Qt::UserRole);
model->setData(index, value, Qt::DisplayRole);
}
}
 
void PropTreeItemDelegate::destroyEditor(QWidget * editor, const QModelIndex & index) const
{
m_edit = NULL;
PropTreeItem* item = (PropTreeItem*)m_parent->indexToItem(index);
if (item)
emit item->editFinished();
QAbstractItemDelegate::destroyEditor(editor, index);
}
 
void PropTreeItemDelegate::valueHasChanged()
{
emit commitData(m_edit);
}
 
void PropTreeItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
{
editor->setGeometry(option.rect);
}
 
QSize PropTreeItemDelegate::sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const
{
QSize sz = QItemDelegate::sizeHint(opt, index) + QSize(2, 6);
return sz;
}
 
PropTreeItem::PropTreeItem(QTreeWidget *parent, int typ, QString title) : QObject(parent), QTreeWidgetItem(parent)
{
setText(0, title);
m_type = typ;
m_comboIndex = -1;
m_unit = 0;
m_decimals = 0;
setData(0, Qt::UserRole, 0);
setData(1, Qt::UserRole, 0);
if (typ > 0)
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
else
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
}
 
PropTreeItem::PropTreeItem(PropTreeItem *parent, int typ, QString title) : QObject(parent), QTreeWidgetItem(parent)
{
setText(0, title);
m_type = typ;
m_comboIndex = -1;
m_unit = 0;
m_decimals = 0;
setData(0, Qt::UserRole, 0);
setData(1, Qt::UserRole, 0);
if (typ > 0)
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsEditable);
else
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
}
 
int PropTreeItem::valueAsInt()
{
int val = 0;
val = data(1, Qt::UserRole).toInt();
return val;
}
 
double PropTreeItem::valueAsDouble()
{
return data(1, Qt::UserRole).toDouble();
}
 
bool PropTreeItem::valueAsBool()
{
return data(1, Qt::UserRole).toBool();
}
 
QString PropTreeItem::valueAsString()
{
return data(1, Qt::UserRole).toString();
}
 
void PropTreeItem::setIntValue(int value)
{
if (m_type == ComboBox)
{
m_comboIndex = value;
QStringList vals = data(1, Qt::UserRole + 1).toStringList();
if (value < vals.count())
{
setData(1, Qt::UserRole, vals[value]);
setData(1, Qt::DisplayRole, vals[value]);
}
}
else
{
setData(1, Qt::UserRole, value);
setData(1, Qt::DisplayRole, QString("%1 %2").arg(value).arg(unitGetSuffixFromIndex(m_unit)));
}
}
 
void PropTreeItem::setDoubleValue(double value)
{
setData(1, Qt::UserRole, value);
setData(1, Qt::DisplayRole, QString("%1 %2").arg(value, 0, 'f', m_decimals).arg(unitGetSuffixFromIndex(m_unit)));
}
 
void PropTreeItem::setBoolValue(bool value)
{
setData(1, Qt::UserRole, value);
setData(1, Qt::DisplayRole, value);
}
 
void PropTreeItem::setStringValue(QString value)
{
setData(1, Qt::UserRole, value);
setData(1, Qt::DisplayRole, value);
}
 
void PropTreeItem::setUnitValue(int unit)
{
m_unit = unit;
if (m_type == DoubleSpinBox)
setData(1, Qt::DisplayRole, QString("%1 %2").arg(data(1, Qt::UserRole).toDouble(), 0, 'f', m_decimals).arg(unitGetSuffixFromIndex(m_unit)));
else
setData(1, Qt::DisplayRole, QString("%1 %2").arg(data(1, Qt::UserRole).toString()).arg(unitGetSuffixFromIndex(m_unit)));
}
 
void PropTreeItem::setDecimalsValue(int unit)
{
m_decimals = unit;
if (m_type == DoubleSpinBox)
setData(1, Qt::DisplayRole, QString("%1 %2").arg(data(1, Qt::UserRole).toDouble(), 0, 'f', unit).arg(unitGetSuffixFromIndex(m_unit)));
else
setData(1, Qt::DisplayRole, QString("%1 %2").arg(data(1, Qt::UserRole).toString()).arg(unitGetSuffixFromIndex(m_unit)));
}
 
void PropTreeItem::setComboStrings(QStringList value)
{
setData(1, Qt::UserRole + 1, value);
}
 
void PropTreeItem::setMinMaxValues(int min, int max)
{
m_min = min;
m_max = max;
}
 
void PropTreeItem::setMinMaxValues(double min, double max)
{
m_fmin = min;
m_fmax = max;
}
 
void PropTreeItem::setColorList(ColorList colors)
{
m_colors = colors;
}
 
PropTreeWidget::PropTreeWidget(QWidget* pa) : QTreeWidget(pa)
{
setFocusPolicy(Qt::NoFocus);
setColumnCount(2);
delegate = new PropTreeItemDelegate(this);
setItemDelegate(delegate);
setRootIsDecorated(false);
setIndentation(0);
header()->hide();
header()->setSectionResizeMode(QHeaderView::Stretch);
setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
setEditTriggers(QAbstractItemView::DoubleClicked | QAbstractItemView::CurrentChanged | QAbstractItemView::SelectedClicked);
connect(this, SIGNAL(itemClicked(QTreeWidgetItem*,int)), this, SLOT(handleMousePress(QTreeWidgetItem*)));
}
 
void PropTreeWidget::handleMousePress(QTreeWidgetItem *item)
{
if (item == NULL)
return;
if (item->parent() == NULL)
{
if (!(item->flags() & Qt::ItemIsEditable))
setItemExpanded(item, !isItemExpanded(item));
}
}
 
void PropTreeWidget::mousePressEvent(QMouseEvent *event)
{
QTreeWidgetItem *item = itemAt(event->pos());
if (item)
{
if (item->flags() & Qt::ItemIsEditable)
{
if ((event->button() == Qt::LeftButton) && (header()->logicalIndexAt(event->pos().x()) == 1))
QTreeWidget::mousePressEvent(event);
else
event->ignore();
}
else
QTreeWidget::mousePressEvent(event);
}
else
QTreeWidget::mousePressEvent(event);
}
 
PropTreeItem* PropTreeWidget::indexToItem(const QModelIndex &index)
{
return (PropTreeItem*)itemFromIndex(index);
}
 
void PropTreeWidget::drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QStyleOptionViewItemV3 opt = option;
QTreeWidget::drawRow(painter, opt, index);
QColor color = static_cast<QRgb>(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &opt));
painter->save();
painter->setPen(QPen(color));
painter->drawLine(opt.rect.x(), opt.rect.bottom(), opt.rect.right(), opt.rect.bottom());
painter->restore();
}
/trunk/Scribus/scribus/ui/proptree.h
0,0 → 1,129
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
proptree.h - description
-------------------
begin : Mon Feb 3 2014
copyright : (C) 2008 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
 
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
 
#ifndef PROPTREE_H
#define PROPTREE_H
 
#include <QItemDelegate>
#include <QTreeWidget>
#include <QString>
#include <QWidget>
#include <QHash>
#include <QEvent>
#include "scribusapi.h"
#include "sccolor.h"
class PropTreeWidget;
 
class SCRIBUS_API PropTreeItemDelegate : public QItemDelegate
{
Q_OBJECT
 
public:
PropTreeItemDelegate(PropTreeWidget *parent);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void destroyEditor(QWidget * editor, const QModelIndex & index) const;
void updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, const QModelIndex &index) const;
QSize sizeHint(const QStyleOptionViewItem &opt, const QModelIndex &index) const;
private slots:
void valueHasChanged();
private:
PropTreeWidget *m_parent;
mutable QWidget *m_edit;
};
 
class SCRIBUS_API PropTreeItem : public QObject, public QTreeWidgetItem
{
Q_OBJECT
 
public:
PropTreeItem(QTreeWidget* parent, int typ, QString title);
PropTreeItem(PropTreeItem* parent, int typ, QString title);
// PropTreeItem(QTreeWidget *parent, QString title, int value, int min, int max, int unit);
// PropTreeItem(QTreeWidget* parent, QString title, double value, double min, double max, int decimals, int unit);
// PropTreeItem(QTreeWidget *parent, QString title, QString value, QStringList values);
// PropTreeItem(QTreeWidget* parent, QString title, bool value);
// PropTreeItem(QTreeWidget *parent, QString title, QString value);
~PropTreeItem() {};
enum PropItemType
{
Title = 0,
IntSpinBox = 1,
DoubleSpinBox = 2,
ComboBox = 3,
CheckBox = 4,
ColorCombo = 5
};
 
int valueAsInt();
double valueAsDouble();
bool valueAsBool();
QString valueAsString();
void setIntValue(int value);
void setDoubleValue(double value);
void setBoolValue(bool value);
void setStringValue(QString value);
void setUnitValue(int unit);
void setDecimalsValue(int unit);
void setComboStrings(QStringList value);
void setMinMaxValues(int min, int max);
void setMinMaxValues(double min, double max);
void setColorList(ColorList colors);
int m_type;
int m_unit;
int m_decimals;
double m_fmin;
double m_fmax;
int m_min;
int m_max;
int m_comboIndex;
ColorList m_colors;
 
signals:
void valueChanged(int);
void valueChanged(double);
void valueChanged(bool);
void valueChanged(QString);
void editFinished();
void editStarted();
};
 
class SCRIBUS_API PropTreeWidget : public QTreeWidget
{
Q_OBJECT
public:
PropTreeWidget(QWidget* pa);
PropTreeItem* indexToItem(const QModelIndex &index);
~PropTreeWidget() {};
protected:
void mousePressEvent(QMouseEvent *event);
void drawRow(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const;
private:
PropTreeItemDelegate *delegate;
private slots:
void handleMousePress(QTreeWidgetItem *item);
};
 
#endif // PROPTREE_H
/trunk/Scribus/scribus/ui/sctreewidget.cpp
30,7 → 30,6
 
#include "sctreewidget.h"
 
 
ScTreeWidgetDelegate::ScTreeWidgetDelegate(QTreeWidget *view, QWidget *parent) : QItemDelegate(parent), m_view(view)
{
}
130,9 → 129,12
QTreeWidgetItem *item2 = new QTreeWidgetItem(item1);
item2->setFlags(Qt::ItemIsEnabled);
// hack to work around a bug in Qt-4.3.4
widget->layout()->activate();
widget->setMinimumSize(widget->layout()->minimumSize());
item2->setSizeHint(0, widget->layout()->minimumSize());
if (widget->layout())
{
widget->layout()->activate();
widget->setMinimumSize(widget->layout()->minimumSize());
item2->setSizeHint(0, widget->layout()->minimumSize());
}
// end hack
setItemWidget(item2, 0, widget);
QKeySequence newMnemonic = QKeySequence::mnemonic(title);