Rev 16318 |
Rev 16968 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
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.
*/
#include "propertywidget_pos.h"
#if defined(_MSC_VER)
#define _USE_MATH_DEFINES
#endif
#include <cmath>
#include "basepointwidget.h"
#include "commonstrings.h"
#include "colorlistbox.h"
#include "sccolorengine.h"
#include "pageitem.h"
#include "pageitem_arc.h"
#include "pageitem_spiral.h"
#include "pageitem_textframe.h"
#include "propertiespalette_utils.h"
#include "sccombobox.h"
#include "scribus.h"
#include "scribuscore.h"
#include "scraction.h"
#include "scribusview.h"
#include "selection.h"
#include "tabmanager.h"
#include "units.h"
#include "undomanager.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "text/nlsconfig.h"
//using namespace std;
PropertyWidget_Position::PropertyWidget_Position( QWidget* parent) : QGroupBox(parent)
{
m_ScMW = 0;
m_doc = 0;
m_item = 0;
m_lineMode = false;
m_oldRotation = 0;
m_unitIndex = 0;
m_unitRatio = 1.0;
setupUi(this);
setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
_userActionOn = false;
userActionSniffer = new UserActionSniffer(this);
connect(userActionSniffer, SIGNAL(actionStart()), this, SLOT(spinboxStartUserAction()));
connect(userActionSniffer, SIGNAL(actionEnd()), this, SLOT(spinboxFinishUserAction()));
installSniffer(xposSpin);
installSniffer(yposSpin);
installSniffer(widthSpin);
installSniffer(heightSpin);
xposLabel->setBuddy(xposSpin);
yposLabel->setBuddy(yposSpin);
widthLabel->setBuddy(widthSpin);
heightLabel->setBuddy(heightSpin);
keepFrameWHRatioButton->setCheckable( true );
keepFrameWHRatioButton->setAutoRaise( true );
keepFrameWHRatioButton->setMaximumSize( QSize( 15, 32767 ) );
keepFrameWHRatioButton->setChecked(false);
rotationSpin->setNewUnit(6);
rotationSpin->setWrapping( true );
installSniffer(rotationSpin);
rotationLabel->setPixmap(loadIcon("Rotieren2.png"));
rotationLabel->setBuddy(rotationSpin);
numObjsLabel->setAlignment( Qt::AlignLeft | Qt::AlignVCenter );
doGroup->setIcon(QIcon(loadIcon("group.png")));
doUngroup->setIcon(QIcon(loadIcon("ungroup.png")));
flipH->setIcon(QIcon(loadIcon("16/flip-object-horizontal.png")));
flipH->setCheckable( true );
flipV->setIcon(QIcon(loadIcon("16/flip-object-vertical.png")));
flipV->setCheckable( true );
doLock->setCheckable( true );
QIcon a = QIcon();
a.addPixmap(loadIcon("16/lock.png"), QIcon::Normal, QIcon::On);
a.addPixmap(loadIcon("16/lock-unlocked.png"), QIcon::Normal, QIcon::Off);
doLock->setIcon(a);
noPrint->setCheckable( true );
QIcon a2 = QIcon();
a2.addPixmap(loadIcon("NoPrint.png"), QIcon::Normal, QIcon::On);
a2.addPixmap(loadIcon("16/document-print.png"), QIcon::Normal, QIcon::Off);
noPrint->setIcon(a2);
noResize->setCheckable( true );
QIcon a3 = QIcon();
a3.addPixmap(loadIcon("framenoresize.png"), QIcon::Normal, QIcon::On);
a3.addPixmap(loadIcon("frameresize.png"), QIcon::Normal, QIcon::Off);
noResize->setIcon(a3);
m_lineMode = false;
languageChange();
xposSpin->showValue(0);
yposSpin->showValue(0);
widthSpin->showValue(0);
heightSpin->showValue(0);
rotationSpin->showValue(0);
setEnabled(false);
}
void PropertyWidget_Position::changeEvent(QEvent *e)
{
if (e->type() == QEvent::LanguageChange)
{
languageChange();
return;
}
QWidget::changeEvent(e);
}
void PropertyWidget_Position::connectSignals()
{
connect(xposSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewX()), Qt::UniqueConnection);
connect(yposSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewY()), Qt::UniqueConnection);
connect(widthSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewW()), Qt::UniqueConnection);
connect(heightSpin , SIGNAL(valueChanged(double)), this, SLOT(handleNewH()), Qt::UniqueConnection);
connect(rotationSpin, SIGNAL(valueChanged(double)), this, SLOT(handleRotation()), Qt::UniqueConnection);
connect(flipH , SIGNAL(clicked()) , this, SLOT(handleFlipH()), Qt::UniqueConnection);
connect(flipV , SIGNAL(clicked()) , this, SLOT(handleFlipV()), Qt::UniqueConnection);
/*connect(levelUp , SIGNAL(clicked()) , this, SLOT(handleRaise()), Qt::UniqueConnection);
connect(levelDown , SIGNAL(clicked()) , this, SLOT(handleLower()), Qt::UniqueConnection);
connect(levelTop , SIGNAL(clicked()) , this, SLOT(handleFront()), Qt::UniqueConnection);
connect(levelBottom , SIGNAL(clicked()) , this, SLOT(handleBack()) , Qt::UniqueConnection);*/
connect(basePointWidget, SIGNAL(buttonClicked(int)), this, SLOT(handleBasePoint(int)), Qt::UniqueConnection);
connect(doLock , SIGNAL(clicked()), this, SLOT(handleLock()) , Qt::UniqueConnection);
connect(noPrint , SIGNAL(clicked()), this, SLOT(handlePrint()) , Qt::UniqueConnection);
connect(noResize , SIGNAL(clicked()), this, SLOT(handleLockSize()) , Qt::UniqueConnection);
connect(doGroup , SIGNAL(clicked()), this, SLOT(handleGrouping()) , Qt::UniqueConnection);
connect(doUngroup , SIGNAL(clicked()), this, SLOT(handleUngrouping()), Qt::UniqueConnection );
}
void PropertyWidget_Position::disconnectSignals()
{
disconnect(xposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewX()));
disconnect(yposSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewY()));
disconnect(widthSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewW()));
disconnect(heightSpin, SIGNAL(valueChanged(double)), this, SLOT(handleNewH()));
disconnect(rotationSpin, SIGNAL(valueChanged(double)), this, SLOT(handleRotation()));
disconnect(flipH, SIGNAL(clicked()), this, SLOT(handleFlipH()));
disconnect(flipV, SIGNAL(clicked()), this, SLOT(handleFlipV()));
/*disconnect(levelUp, SIGNAL(clicked()), this, SLOT(handleRaise()));
disconnect(levelDown, SIGNAL(clicked()), this, SLOT(handleLower()));
disconnect(levelTop, SIGNAL(clicked()), this, SLOT(handleFront()));
disconnect(levelBottom, SIGNAL(clicked()), this, SLOT(handleBack()));*/
disconnect(basePointWidget, SIGNAL(buttonClicked(int)), this, SLOT(handleBasePoint(int)));
disconnect(doLock , SIGNAL(clicked()), this, SLOT(handleLock()));
disconnect(noPrint , SIGNAL(clicked()), this, SLOT(handlePrint()));
disconnect(noResize , SIGNAL(clicked()), this, SLOT(handleLockSize()));
disconnect(doGroup , SIGNAL(clicked()), this, SLOT(handleGrouping()) );
disconnect(doUngroup, SIGNAL(clicked()), this, SLOT(handleUngrouping()) );
}
void PropertyWidget_Position::enableFromSelection(void)
{
bool enabled = false;
if (!m_item || !m_doc)
{
xposSpin->setConstants(NULL);
yposSpin->setConstants(NULL);
widthSpin->setConstants(NULL);
heightSpin->setConstants(NULL);
doGroup->setEnabled(false);
doUngroup->setEnabled(false);
flipH->setEnabled(false);
flipV->setEnabled(false);
xposLabel->setText( tr( "&X" ) );
yposLabel->setText( tr( "&Y" ) );
widthLabel->setText( tr( "&W" ) );
heightLabel->setText( tr( "&H" ) );
xposSpin->showValue(0);
yposSpin->showValue(0);
widthSpin->showValue(0);
heightSpin->showValue(0);
rotationSpin->showValue(0);
setEnabled(false);
return;
}
if (m_doc->m_Selection->count() > 1)
{
xposSpin->setEnabled(true);
yposSpin->setEnabled(true);
widthSpin->setEnabled(true);
heightSpin->setEnabled(true);
rotationSpin->setEnabled(true);
flipH->setEnabled(true);
flipV->setEnabled(true);
flipH->setCheckable(false);
flipV->setCheckable(false);
flipH->setChecked(false);
flipV->setChecked(false);
enabled = true;
}
else
{
flipH->setEnabled(true);
flipV->setEnabled(true);
//CB If Toggle is not possible, then we need to enable it so we can turn it off
//It then gets reset below for items where its valid
int itemType = m_item->itemType();
bool checkableFlip = false;
checkableFlip |= m_item->isGroup();
checkableFlip |= m_item->isImageFrame();
checkableFlip |= m_item->isTextFrame();
checkableFlip |= m_item->isLatexFrame();
checkableFlip |= m_item->isOSGFrame();
checkableFlip |= m_item->isSpiral();
checkableFlip |= m_item->isSymbol();
flipH->setCheckable(checkableFlip);
flipV->setCheckable(checkableFlip);
if (!checkableFlip)
{
flipH->setChecked(false);
flipV->setChecked(false);
}
basePointWidget->setEnabled(true);
if (m_item->asOSGFrame())
rotationSpin->setEnabled(false);
if (m_item->asLine())
basePointWidget->setEnabled(false);
enabled = true;
}
bool setter = false;
if ((m_item->isTableItem) && (m_item->isSingleSel))
{
setter = true;
rotationSpin->setEnabled(false);
}
xposSpin->setEnabled(!setter);
yposSpin->setEnabled(!setter);
levelSpin->setEnabled(!setter);
if (m_item->asLine())
{
keepFrameWHRatioButton->setEnabled(false);
heightSpin->setEnabled(m_lineMode && !m_item->locked());
}
else
{
heightSpin->setEnabled(true);
keepFrameWHRatioButton->setEnabled(true);
}
doGroup->setEnabled(false);
doUngroup->setEnabled(false);
if (m_doc->m_Selection->count() > 1)
doGroup->setEnabled(true);
if (m_doc->m_Selection->count() == 1)
doUngroup->setEnabled(m_item->isGroup());
noResize->setEnabled(!m_item->isArc());
setEnabled(true);
}
void PropertyWidget_Position::setMainWindow(ScribusMainWindow* mw)
{
m_ScMW = mw;
connect(this, SIGNAL(DocChanged()), m_ScMW, SLOT(slotDocCh()));
}
void PropertyWidget_Position::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;
if (m_doc.isNull())
{
enableFromSelection();
disconnectSignals();
return;
}
m_unitRatio = m_doc->unitRatio();
m_unitIndex = m_doc->unitIndex();
int precision = unitGetPrecisionFromIndex(m_unitIndex);
//qt4 FIXME here
double maxXYWHVal = 16777215 * m_unitRatio;
double minXYVal = -16777215 * m_unitRatio;
QMap<QString, double>* docConstants = m_doc? &m_doc->constants() : NULL;
xposSpin->setValues( minXYVal, maxXYWHVal, precision, minXYVal);
xposSpin->setConstants(docConstants);
yposSpin->setValues( minXYVal, maxXYWHVal, precision, minXYVal);
yposSpin->setConstants(docConstants);
widthSpin->setValues( m_unitRatio, maxXYWHVal, precision, m_unitRatio);
widthSpin->setConstants(docConstants);
heightSpin->setValues( m_unitRatio, maxXYWHVal, precision, m_unitRatio);
heightSpin->setConstants(docConstants);
rotationSpin->setValues( 0, 359.99, 1, 0);
updateSpinBoxConstants();
connect(m_doc->m_Selection, SIGNAL(selectionChanged()), this, SLOT(handleSelectionChanged()));
connect(m_doc , SIGNAL(docChanged()) , this, SLOT(handleSelectionChanged()));
}
void PropertyWidget_Position::setLineMode(int lineMode)
{
if (lineMode == 0)
{
xposLabel->setText( tr( "&X" ) );
yposLabel->setText( tr( "&Y" ) );
widthLabel->setText( tr( "&W" ) );
heightLabel->setText( tr( "&H" ) );
rotationSpin->setEnabled(true);
heightSpin->setEnabled(false);
m_lineMode = false;
}
else
{
xposLabel->setText( tr( "&X1:" ) );
yposLabel->setText( tr( "Y&1:" ) );
widthLabel->setText( tr( "X&2:" ) );
heightLabel->setText( tr( "&Y2:" ) );
rotationSpin->setEnabled(false);
heightSpin->setEnabled(true);
m_lineMode = true;
}
}
void PropertyWidget_Position::setCurrentItem(PageItem *item)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
//CB We shouldnt really need to process this if our item is the same one
//maybe we do if the item has been changed by scripter.. but that should probably
//set some status if so.
//FIXME: This wont work until when a canvas deselect happens, m_item must be NULL.
//if (m_item == i)
// return;
if (item && m_doc.isNull())
setDoc(item->doc());
m_item = item;
disconnectSignals();
enableFromSelection();
if (m_item)
{
int itemCount = m_doc->Items->count();
levelSpin->setMinimum(1);
levelSpin->setMaximum(itemCount);
levelSpin->setValue(m_item->ItemNr + 1);
numObjsLabel->setText( QString("/ %1").arg(itemCount) );
if ((m_item->itemType() == PageItem::Line) && m_lineMode)
{
xposLabel->setText( tr( "&X1" ) );
yposLabel->setText( tr( "Y&1" ) );
widthLabel->setText( tr( "X&2" ) );
heightLabel->setText( tr( "&Y2" ) );
rotationSpin->setEnabled(false);
}
else
{
xposLabel->setText( tr( "&X" ) );
yposLabel->setText( tr( "&Y" ) );
widthLabel->setText( tr( "&W" ) );
heightLabel->setText( tr( "&H" ) );
rotationSpin->setEnabled(!((m_item->isTableItem) && (m_item->isSingleSel)));
}
double selX = m_item->xPos();
double selY = m_item->yPos();
double selW = m_item->width();
double selH = m_item->height();
if (m_doc->m_Selection->count() > 1)
m_doc->m_Selection->getGroupRect(&selX, &selY, &selW, &selH);
displayXY(selX, selY);
displayWH(selW, selH);
displayLocked(m_item->locked());
displaySizeLocked(m_item->sizeLocked());
m_oldRotation = m_item->rotation();
double rr = m_item->rotation();
if (item->rotation() > 0)
rr = 360 - rr;
rotationSpin->showValue(fabs(rr));
noPrint->setChecked(!m_item->printEnabled());
displayFlippedH(m_item->imageFlippedH());
displayFlippedV(m_item->imageFlippedV());
connectSignals();
}
updateSpinBoxConstants();
}
void PropertyWidget_Position::handleSelectionChanged()
{
if (!m_doc || !m_ScMW || m_ScMW->scriptIsRunning())
return;
PageItem* currItem = currentItemFromSelection();
if (m_doc->m_Selection->count() > 1)
{
m_oldRotation = 0;
double gx, gy, gh, gw;
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
int bp = basePointWidget->checkedId();
if (bp == 0)
m_ScMW->view->RCenter = FPoint(gx, gy);
else if (bp == 1)
m_ScMW->view->RCenter = FPoint(gx + gw, gy);
else if (bp == 2)
m_ScMW->view->RCenter = FPoint(gx + gw / 2.0, gy + gh / 2.0);
else if (bp == 3)
m_ScMW->view->RCenter = FPoint(gx, gy + gh);
else if (bp == 0)
m_ScMW->view->RCenter = FPoint(gx + gw, gy + gh);
xposLabel->setText( tr( "&X" ) );
yposLabel->setText( tr( "&Y" ) );
widthLabel->setText( tr( "&W" ) );
heightLabel->setText( tr( "&H" ) );
xposSpin->showValue(gx);
yposSpin->showValue(gy);
widthSpin->showValue(gw);
heightSpin->showValue(gh);
rotationSpin->showValue(0);
}
setCurrentItem(currItem);
updateGeometry();
repaint();
}
void PropertyWidget_Position::displayLevel(uint l)
{
bool blocked = levelSpin->blockSignals(true);
levelSpin->setValue(l + 1);
levelSpin->blockSignals(blocked);
}
void PropertyWidget_Position::displayXY(double x, double y)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
bool useLineMode = false;
double inX, inY, b, h, r, dummy1, dummy2;
QTransform ma;
FPoint n;
if (m_item)
{
if (m_doc->m_Selection->isMultipleSelection())
{
m_doc->m_Selection->getGroupRect(&dummy1, &dummy2, &b, &h);
r = 0.0;
ma.translate(dummy1, dummy2);
}
else
{
b = m_item->width();
h = m_item->height();
r = m_item->rotation();
ma.translate(x, y);
useLineMode = (m_lineMode && m_item->isLine());
}
}
else
{
b = 0.0;
h = 0.0;
r = 0.0;
ma.translate(x, y);
}
ma.rotate(r);
int bp = basePointWidget->checkedId();
// #8890 : basepoint is meaningless when lines use "end points" mode
if (bp == 0 || useLineMode)
n = FPoint(0.0, 0.0);
else if (bp == 1)
n = FPoint(b, 0.0);
else if (bp == 2)
n = FPoint(b / 2.0, h / 2.0);
else if (bp == 3)
n = FPoint(0.0, h);
else if (bp == 4)
n = FPoint(b, h);
inX = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
inY = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
if (m_item)
{
inX -= m_doc->rulerXoffset;
inY -= m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
inX -= m_doc->currentPage()->xOffset();
inY -= m_doc->currentPage()->yOffset();
}
}
xposSpin->showValue(inX*m_unitRatio);
yposSpin->showValue(inY*m_unitRatio);
if (useLineMode)
displayWH(m_item->width(), m_item->height());
}
void PropertyWidget_Position::displayWH(double x, double y)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
if ((m_lineMode) && (m_item->asLine()))
{
QPoint dp;
QTransform ma;
ma.translate(static_cast<double>(xposSpin->value()) / m_unitRatio, static_cast<double>(yposSpin->value()) / m_unitRatio);
ma.rotate(static_cast<double>(rotationSpin->value())*(-1));
// Qt4 dp = ma * QPoint(static_cast<int>(x), static_cast<int>(y));
dp = QPoint(static_cast<int>(x), static_cast<int>(y)) * ma;
widthSpin->showValue(dp.x()*m_unitRatio);
heightSpin->showValue(dp.y()*m_unitRatio);
}
else
{
widthSpin->showValue(x*m_unitRatio);
heightSpin->showValue(y*m_unitRatio);
}
}
void PropertyWidget_Position::displayRotation(double r)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
double rr = r;
if (r > 0)
rr = 360 - rr;
rotationSpin->showValue(fabs(rr));
}
void PropertyWidget_Position::displayLocked(bool isLocked)
{
xposSpin->setReadOnly(isLocked);
yposSpin->setReadOnly(isLocked);
widthSpin->setReadOnly(isLocked);
heightSpin->setReadOnly(isLocked);
rotationSpin->setReadOnly(isLocked);
QPalette pal(qApp->palette());
if (isLocked)
pal.setCurrentColorGroup(QPalette::Disabled);
xposSpin->setPalette(pal);
yposSpin->setPalette(pal);
widthSpin->setPalette(pal);
heightSpin->setPalette(pal);
rotationSpin->setPalette(pal);
levelSpin->setEnabled(!isLocked);
doLock->setChecked(isLocked);
}
void PropertyWidget_Position::displaySizeLocked(bool isSizeLocked)
{
bool b=isSizeLocked;
if (m_item && m_item->locked())
b=true;
widthSpin->setReadOnly(b);
heightSpin->setReadOnly(b);
QPalette pal(qApp->palette());
if (b)
pal.setCurrentColorGroup(QPalette::Disabled);
widthSpin->setPalette(pal);
heightSpin->setPalette(pal);
noResize->setChecked(isSizeLocked);
}
void PropertyWidget_Position::displayPrintingEnabled(bool isPrintingEnabled)
{
noPrint->setChecked(!isPrintingEnabled);
}
void PropertyWidget_Position::displayFlippedH(bool isFlippedH)
{
flipH->setChecked(isFlippedH);
}
void PropertyWidget_Position::displayFlippedV(bool isFlippedV)
{
flipV->setChecked(isFlippedV);
}
void PropertyWidget_Position::handleNewX()
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
if ((m_doc) && (m_item))
{
double x,y,w,h, gx, gy, gh, gw, base;
QTransform ma;
x = xposSpin->value() / m_unitRatio;
y = yposSpin->value() / m_unitRatio;
w = widthSpin->value() / m_unitRatio;
h = heightSpin->value() / m_unitRatio;
base = 0;
x += m_doc->rulerXoffset;
y += m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
x += m_doc->currentPage()->xOffset();
y += m_doc->currentPage()->yOffset();
}
if (m_doc->m_Selection->isMultipleSelection())
{
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
int bp = basePointWidget->checkedId();
if ((bp == 0) || (bp == 3))
base = gx;
else if (bp == 2)
base = gx + gw / 2.0;
else if ((bp == 1) || (bp == 4))
base = gx + gw;
if (!_userActionOn)
m_ScMW->view->startGroupTransaction();
m_doc->moveGroup(x - base, 0, true);
if (!_userActionOn)
{
m_ScMW->view->endGroupTransaction();
}
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
displayXY(gx, gy);
}
else
{
if ((m_item->asLine()) && (m_lineMode))
{
w += m_doc->rulerXoffset;
h += m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
w += m_doc->currentPage()->xOffset();
h += m_doc->currentPage()->yOffset();
}
double r = atan2(h-y,w-x)*(180.0/M_PI);
w = sqrt(pow(w-x,2)+pow(h-y,2));
m_item->setXYPos(x, m_item->yPos(), true);
m_item->setRotation(r, true);
m_doc->SizeItem(w, m_item->height(), m_item, true);
}
else
{
ma.translate(m_item->xPos(), m_item->yPos());
ma.rotate(m_item->rotation());
int bp = basePointWidget->checkedId();
if (bp == 0)
base = m_item->xPos();
else if (bp == 2)
base = ma.m11() * (m_item->width() / 2.0) + ma.m21() * (m_item->height() / 2.0) + ma.dx();
else if (bp == 1)
base = ma.m11() * m_item->width() + ma.m21() * 0.0 + ma.dx();
else if (bp == 4)
base = ma.m11() * m_item->width() + ma.m21() * m_item->height() + ma.dx();
else if (bp == 3)
base = ma.m11() * 0.0 + ma.m21() * m_item->height() + ma.dx();
m_doc->MoveItem(x - base, 0, m_item, true);
}
}
m_doc->regionsChanged()->update(QRect());
emit DocChanged();
}
}
void PropertyWidget_Position::handleNewY()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
double x,y,w,h, gx, gy, gh, gw, base;
QTransform ma;
x = xposSpin->value() / m_unitRatio;
y = yposSpin->value() / m_unitRatio;
w = widthSpin->value() / m_unitRatio;
h = heightSpin->value() / m_unitRatio;
base = 0;
x += m_doc->rulerXoffset;
y += m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
x += m_doc->currentPage()->xOffset();
y += m_doc->currentPage()->yOffset();
}
if (m_doc->m_Selection->isMultipleSelection())
{
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
int bp = basePointWidget->checkedId();
if ((bp == 0) || (bp == 1))
base = gy;
else if (bp == 2)
base = gy + gh / 2.0;
else if ((bp == 3) || (bp == 4))
base = gy + gh;
if (!_userActionOn)
m_ScMW->view->startGroupTransaction();
m_doc->moveGroup(0, y - base, true);
if (!_userActionOn)
{
m_ScMW->view->endGroupTransaction();
}
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
displayXY(gx, gy);
}
else
{
if ((m_item->asLine()) && (m_lineMode))
{
w += m_doc->rulerXoffset;
h += m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
w += m_doc->currentPage()->xOffset();
h += m_doc->currentPage()->yOffset();
}
double r = atan2(h-y,w-x)*(180.0/M_PI);
w = sqrt(pow(w-x,2)+pow(h-y,2));
m_doc->MoveItem(0, y - m_item->yPos(), m_item, true);
m_item->setXYPos(m_item->xPos(), y, true);
m_item->setRotation(r, true);
m_doc->SizeItem(w, m_item->height(), m_item, true);
m_doc->RotateItem(r, m_item);
}
else
{
ma.translate(m_item->xPos(), m_item->yPos());
ma.rotate(m_item->rotation());
int bp = basePointWidget->checkedId();
if (bp == 0)
base = m_item->yPos();
else if (bp == 2)
base = ma.m22() * (m_item->height() / 2.0) + ma.m12() * (m_item->width() / 2.0) + ma.dy();
else if (bp == 1)
base = ma.m22() * 0.0 + ma.m12() * m_item->width() + ma.dy();
else if (bp == 4)
base = ma.m22() * m_item->height() + ma.m12() * m_item->width() + ma.dy();
else if (bp == 3)
base = ma.m22() * m_item->height() + ma.m12() * 0.0 + ma.dy();
m_doc->MoveItem(0, y - base, m_item, true);
}
}
m_doc->regionsChanged()->update(QRect());
emit DocChanged();
}
void PropertyWidget_Position::handleNewW()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
double x,y,w,h, gx, gy, gh, gw;
x = xposSpin->value() / m_unitRatio;
y = yposSpin->value() / m_unitRatio;
w = widthSpin->value() / m_unitRatio;
h = heightSpin->value() / m_unitRatio;
double oldW = (m_item->width() != 0.0) ? m_item->width() : 1.0;
double oldH = (m_item->height() != 0.0) ? m_item->height() : 1.0;
if (m_doc->m_Selection->isMultipleSelection())
{
if (!_userActionOn)
m_ScMW->view->startGroupTransaction();
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
if (keepFrameWHRatioButton->isChecked())
{
m_doc->scaleGroup(w / gw, w / gw, false);
displayWH(w, (w / gw) * gh);
}
else
{
m_doc->scaleGroup(w / gw, 1.0, false);
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
displayWH(gw, gh);
}
if (!_userActionOn)
{
m_ScMW->view->endGroupTransaction();
}
}
else
{
bool oldS = m_item->Sizing;
m_item->Sizing = false;
m_item->OldB2 = m_item->width();
m_item->OldH2 = m_item->height();
if (m_item->asLine())
{
if (m_lineMode)
{
double r = atan2(h-y,w-x)*(180.0/M_PI);
m_item->setRotation(r, true);
w = sqrt(pow(w-x,2)+pow(h-y,2));
}
m_doc->SizeItem(w, m_item->height(), m_item, true, true, false);
}
else
{
if (m_item->isTableItem)
{
int rmo = m_doc->RotMode();
m_doc->RotMode ( 0 );
double dist = w - m_item->width();
PageItem* bb2;
PageItem* bb = m_item;
while (bb->TopLink != 0)
{
bb = bb->TopLink;
}
while (bb->BottomLink != 0)
{
bb2 = bb;
while (bb2->RightLink != 0)
{
m_doc->MoveRotated(bb2->RightLink, FPoint(dist, 0), true);
bb2 = bb2->RightLink;
}
m_doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb, true);
bb = bb->BottomLink;
}
bb2 = bb;
while (bb2->RightLink != 0)
{
m_doc->MoveRotated(bb2->RightLink, FPoint(dist, 0), true);
bb2 = bb2->RightLink;
}
m_doc->MoveSizeItem(FPoint(0, 0), FPoint(-dist, 0), bb, true);
m_doc->RotMode ( rmo );
if (keepFrameWHRatioButton->isChecked())
{
keepFrameWHRatioButton->setChecked(false);
displayWH(w, (w / oldW) * m_item->height());
handleNewH();
keepFrameWHRatioButton->setChecked(true);
}
}
else
{
if (keepFrameWHRatioButton->isChecked())
{
displayWH(w, (w / oldW) * m_item->height());
m_doc->SizeItem(w, (w / oldW) * m_item->height(), m_item, true, true, false);
}
else
m_doc->SizeItem(w, m_item->height(), m_item, true, true, false);
}
}
if (m_item->isArc())
{
double dw = w - oldW;
double dh = h - oldH;
PageItem_Arc* item = m_item->asArc();
double dsch = item->arcHeight / oldH;
double dscw = item->arcWidth / oldW;
item->arcWidth += dw * dscw;
item->arcHeight += dh * dsch;
item->recalcPath();
FPoint tp2(getMinClipF(&m_item->PoLine));
m_item->PoLine.translate(-tp2.x(), -tp2.y());
m_doc->AdjustItemSize(m_item);
}
if (m_item->isSpiral())
{
PageItem_Spiral* item = m_item->asSpiral();
item->recalcPath();
}
m_item->Sizing = oldS;
}
//emit DocChanged();
m_doc->changed();
m_doc->regionsChanged()->update(QRect());
}
void PropertyWidget_Position::handleNewH()
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
if ((m_doc) && (m_item))
{
double x,y,w,h, gx, gy, gh, gw;
x = xposSpin->value() / m_unitRatio;
y = yposSpin->value() / m_unitRatio;
w = widthSpin->value() / m_unitRatio;
h = heightSpin->value() / m_unitRatio;
double oldW = (m_item->width() != 0.0) ? m_item->width() : 1.0;
double oldH = (m_item->height() != 0.0) ? m_item->height() : 1.0;
if (m_doc->m_Selection->isMultipleSelection())
{
if (!_userActionOn)
m_ScMW->view->startGroupTransaction();
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
if (keepFrameWHRatioButton->isChecked())
{
m_doc->scaleGroup(h / gh, h / gh, false);
displayWH((h / gh) * gw, h);
}
else
{
m_doc->scaleGroup(1.0, h / gh, false);
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
displayWH(gw, gh);
}
if (!_userActionOn)
{
m_ScMW->view->endGroupTransaction();
}
}
else
{
bool oldS = m_item->Sizing;
m_item->Sizing = false;
m_item->OldB2 = m_item->width();
m_item->OldH2 = m_item->height();
if (m_item->asLine())
{
if (m_lineMode)
{
double r = atan2(h-y,w-x)*(180.0/M_PI);
m_item->setRotation(r, true);
w = sqrt(pow(w-x,2)+pow(h-y,2));
}
m_doc->SizeItem(w, m_item->height(), m_item, true, true, false);
}
else
{
if (m_item->isTableItem)
{
int rmo = m_doc->RotMode();
m_doc->RotMode ( 0 );
double dist = h - m_item->height();
PageItem* bb2;
PageItem* bb = m_item;
while (bb->LeftLink != 0)
{
bb = bb->LeftLink;
}
while (bb->RightLink != 0)
{
bb2 = bb;
while (bb2->BottomLink != 0)
{
m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true);
bb2 = bb2->BottomLink;
}
m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true);
bb = bb->RightLink;
}
bb2 = bb;
while (bb2->BottomLink != 0)
{
m_doc->MoveRotated(bb2->BottomLink, FPoint(0, dist), true);
bb2 = bb2->BottomLink;
}
m_doc->MoveSizeItem(FPoint(0, 0), FPoint(0, -dist), bb, true);
m_doc->RotMode ( rmo );
if (keepFrameWHRatioButton->isChecked())
{
keepFrameWHRatioButton->setChecked(false);
displayWH((h / oldH) * m_item->width(), h);
handleNewW();
keepFrameWHRatioButton->setChecked(true);
}
}
else
{
if (keepFrameWHRatioButton->isChecked())
{
displayWH((h / oldH) * m_item->width(), h);
m_doc->SizeItem((h / oldH) * m_item->width(), h, m_item, true, true, false);
}
else
m_doc->SizeItem(m_item->width(), h, m_item, true, true, false);
}
}
if (m_item->isArc())
{
double dw = w - oldW;
double dh = h - oldH;
PageItem_Arc* item = m_item->asArc();
double dsch = item->arcHeight / oldH;
double dscw = item->arcWidth / oldW;
item->arcWidth += dw * dscw;
item->arcHeight += dh * dsch;
item->recalcPath();
FPoint tp2(getMinClipF(&m_item->PoLine));
m_item->PoLine.translate(-tp2.x(), -tp2.y());
m_doc->AdjustItemSize(m_item);
}
if (m_item->isSpiral())
{
PageItem_Spiral* item = m_item->asSpiral();
item->recalcPath();
}
m_item->Sizing = oldS;
}
//emit DocChanged();
m_doc->changed();
m_doc->regionsChanged()->update(QRect());
}
}
void PropertyWidget_Position::handleRotation()
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
double gx, gy, gh, gw;
if ((m_doc) && (m_item))
{
if (!_userActionOn)
m_ScMW->view->startGroupTransaction(Um::Rotate, "", Um::IRotate);
if (m_doc->m_Selection->isMultipleSelection())
{
m_doc->rotateGroup((rotationSpin->value() - m_oldRotation)*(-1), m_ScMW->view->RCenter);
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
displayXY(gx, gy);
}
else
m_doc->RotateItem(rotationSpin->value()*(-1), m_item);
if (!_userActionOn)
{
for (int i = 0; i < m_doc->m_Selection->count(); ++i)
m_doc->m_Selection->itemAt(i)->checkChanges(true);
m_ScMW->view->endGroupTransaction();
}
emit DocChanged();
m_doc->regionsChanged()->update(QRect());
m_oldRotation = rotationSpin->value();
}
}
void PropertyWidget_Position::handleLower()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->view->LowerItem();
}
void PropertyWidget_Position::handleRaise()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->view->RaiseItem();
}
void PropertyWidget_Position::handleFront()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->view->ToFront();
}
void PropertyWidget_Position::handleBack()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->view->ToBack();
}
void PropertyWidget_Position::handleBasePoint(int m)
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
double inX, inY, gx, gy, gh, gw;
inX = 0;
inY = 0;
if ((m_doc) && (m_item))
{
m_doc->RotMode ( m );
if (m_doc->m_Selection->isMultipleSelection())
{
m_doc->m_Selection->setGroupRect();
m_doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
if (m == 0)
{
m_ScMW->view->RCenter = FPoint(gx, gy);
inX = gx;
inY = gy;
}
if (m == 1)
{
m_ScMW->view->RCenter = FPoint(gx+gw, gy);
inX = gx+gw;
inY = gy;
}
if (m == 2)
{
m_ScMW->view->RCenter = FPoint(gx + gw / 2.0, gy + gh / 2.0);
inX = gx + gw / 2.0;
inY = gy + gh / 2.0;
}
if (m == 3)
{
m_ScMW->view->RCenter = FPoint(gx, gy+gh);
inX = gx;
inY = gy+gh;
}
if (m == 4)
{
m_ScMW->view->RCenter = FPoint(gx+gw, gy+gh);
inX = gx+gw;
inY = gy+gh;
}
inX -= m_doc->rulerXoffset;
inY -= m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
inX -= m_doc->currentPage()->xOffset();
inY -= m_doc->currentPage()->yOffset();
}
xposSpin->setValue(inX*m_unitRatio);
yposSpin->setValue(inY*m_unitRatio);
}
else
{
double b, h, r;
QTransform ma;
FPoint n;
b = m_item->width();
h = m_item->height();
r = m_item->rotation();
ma.translate(m_item->xPos(), m_item->yPos());
ma.rotate(r);
int bp = basePointWidget->checkedId();
if (bp == 0)
n = FPoint(0.0, 0.0);
else if (bp == 1)
n = FPoint(b, 0.0);
else if (bp == 2)
n = FPoint(b / 2.0, h / 2.0);
else if (bp == 3)
n = FPoint(0.0, h);
else if (bp == 4)
n = FPoint(b, h);
inX = ma.m11() * n.x() + ma.m21() * n.y() + ma.dx();
inY = ma.m22() * n.y() + ma.m12() * n.x() + ma.dy();
inX -= m_doc->rulerXoffset;
inY -= m_doc->rulerYoffset;
if (m_doc->guidesPrefs().rulerMode)
{
inX -= m_doc->currentPage()->xOffset();
inY -= m_doc->currentPage()->yOffset();
}
xposSpin->setValue(inX*m_unitRatio);
yposSpin->setValue(inY*m_unitRatio);
}
if (m_item->itemType() == PageItem::ImageFrame)
{
// FIXME
if (false /*!FreeScale->isChecked()*/)
{
m_item->AdjustPictScale();
m_item->update();
emit DocChanged();
}
}
}
}
void PropertyWidget_Position::handleLock()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->scrActions["itemLock"]->toggle();
}
void PropertyWidget_Position::handleLockSize()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->scrActions["itemLockSize"]->toggle();
}
void PropertyWidget_Position::handlePrint()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->scrActions["itemPrintingEnabled"]->toggle();
}
void PropertyWidget_Position::handleFlipH()
{
if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->scrActions["itemFlipH"]->toggle();
}
void PropertyWidget_Position::handleFlipV()
{
if (!m_ScMW || m_ScMW->scriptIsRunning())
return;
m_ScMW->scrActions["itemFlipV"]->toggle();
}
void PropertyWidget_Position::handleGrouping()
{
m_ScMW->GroupObj();
doGroup->setEnabled(false);
doUngroup->setEnabled(true);
handleSelectionChanged();
//FIXME
//TabStack->setItemEnabled(idShapeItem, false);
}
void PropertyWidget_Position::handleUngrouping()
{
m_ScMW->UnGroupObj();
}
void PropertyWidget_Position::updateSpinBoxConstants()
{
if (m_doc.isNull())
return;
if (m_doc->m_Selection->count()==0)
return;
widthSpin->setConstants(&m_doc->constants());
heightSpin->setConstants(&m_doc->constants());
xposSpin->setConstants(&m_doc->constants());
yposSpin->setConstants(&m_doc->constants());
}
void PropertyWidget_Position::languageChange()
{
setTitle( tr("Position"));
xposLabel->setText( tr("&X"));
yposLabel->setText( tr("&Y"));
widthLabel->setText( tr("&W"));
heightLabel->setText( tr("&H"));
levelLabel->setText( tr("Level"));
QString ptSuffix = tr(" pt");
QString suffix = (m_doc) ? unitGetSuffixFromIndex(m_doc->unitIndex()) : ptSuffix;
xposSpin->setSuffix(suffix);
yposSpin->setSuffix(suffix);
widthSpin->setSuffix(suffix);
heightSpin->setSuffix(suffix);
xposSpin->setToolTip( tr("Horizontal position of current basepoint"));
yposSpin->setToolTip( tr("Vertical position of current basepoint"));
widthSpin->setToolTip( tr("Width"));
heightSpin->setToolTip( tr("Height"));
rotationSpin->setToolTip( tr("Rotation of object at current basepoint"));
basePointWidget->setToolTip( tr("Point from which measurements or rotation angles are referenced"));
doGroup->setToolTip( tr("Group the selected objects"));
doUngroup->setToolTip( tr("Ungroup the selected group"));
flipH->setToolTip( tr("Flip Horizontal"));
flipV->setToolTip( tr("Flip Vertical"));
levelSpin->setToolTip( tr("Indicates the level the object is on, 0 means the object is at the bottom"));
doLock->setToolTip( tr("Lock or unlock the object"));
noResize->setToolTip( tr("Lock or unlock the size of the object"));
noPrint->setToolTip( tr("Enable or disable exporting of the object"));
keepFrameWHRatioButton->setToolTip( tr("Keep the aspect ratio"));
}
void PropertyWidget_Position::unitChange()
{
if (!m_doc)
return;
double oldRatio = m_unitRatio;
m_unitRatio = m_doc->unitRatio();
m_unitIndex = m_doc->unitIndex();
bool xSigBlocked = xposSpin->blockSignals(true);
bool ySigBlocked = yposSpin->blockSignals(true);
bool wSigBlocked = widthSpin->blockSignals(true);
bool hSigBlocked = heightSpin->blockSignals(true);
xposSpin->setNewUnit( m_unitIndex );
yposSpin->setNewUnit( m_unitIndex );
widthSpin->setNewUnit( m_unitIndex );
heightSpin->setNewUnit( m_unitIndex );
xposSpin->blockSignals(xSigBlocked);
yposSpin->blockSignals(ySigBlocked);
widthSpin->blockSignals(wSigBlocked);
heightSpin->blockSignals(hSigBlocked);
}
void PropertyWidget_Position::installSniffer(ScrSpinBox *spinBox)
{
const QList<QObject*> list = spinBox->children();
if (!list.isEmpty())
{
QListIterator<QObject*> it(list);
QObject *obj;
while (it.hasNext())
{
obj = it.next();
obj->installEventFilter(userActionSniffer);
}
}
}
bool PropertyWidget_Position::userActionOn()
{
return _userActionOn;
}
void PropertyWidget_Position::spinboxStartUserAction()
{
_userActionOn = true;
}
void PropertyWidget_Position::spinboxFinishUserAction()
{
_userActionOn = false;
for (int i = 0; i < m_doc->m_Selection->count(); ++i)
m_doc->m_Selection->itemAt(i)->checkChanges(true);
if (m_ScMW->view->groupTransactionStarted())
{
m_ScMW->view->endGroupTransaction();
}
}