Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 4214 → Rev 4215

/branches/Version13x/Scribus/scribus/guidemanager.cpp
43,6 → 43,21
extern QPixmap loadIcon(QString nam);
 
 
int GuideListItem::compare(QListViewItem *i, int col, bool asc) const
{
if (col == 0)
{
double d;
d = text(col).toDouble() - i->text(col).toDouble();
if (d > 0.0)
return 1;
return -1;
}
else
return QListViewItem::compare(i, col, asc);
}
 
 
GuideManager::GuideManager(QWidget* parent) : QDialog(parent, "GuideManager", true, 0)
{
setCaption( tr("Manage Guides"));
57,7 → 72,8
suffix = unitGetSuffixFromIndex(docUnitIndex);
 
/* Create the dialog elements */
QVBoxLayout *guideManagerLayout = new QVBoxLayout(this, 11, 6, "guideManagerLayout");
QHBoxLayout *guideManagerLayout = new QHBoxLayout(this, 11, 6, "guideManagerLayout");
QVBoxLayout *mainWidgetsLayout = new QVBoxLayout(0, 11, 6, "mainWidgetsLayout");
 
QHBoxLayout *Layout6 = new QHBoxLayout(0, 0, 6, "Layout6");
 
145,7 → 161,7
 
Layout6->addWidget(verGroup);
 
guideManagerLayout->addLayout(Layout6);
mainWidgetsLayout->addLayout(Layout6);
 
QHBoxLayout *Layout7 = new QHBoxLayout(0, 0, 6, "Layout7");
 
216,7 → 232,7
horGroupLayout2->addLayout(autoGuidesLayout);
horGroupLayout2->addLayout(Layout10);
 
guideManagerLayout->addLayout(Layout7);
mainWidgetsLayout->addLayout(Layout7);
 
QHBoxLayout *Layout5 = new QHBoxLayout(0, 0, 6, "Layout5");
lockedCheckBox = new QCheckBox( tr( "&Lock Guides" ), this, "lockedCheckBox");
242,13 → 258,31
buttonLayout->addWidget(okButton);
buttonLayout->addWidget(cancelButton);
 
guideManagerLayout->addLayout(Layout5);
guideManagerLayout->addLayout(buttonLayout);
mainWidgetsLayout->addLayout(Layout5);
mainWidgetsLayout->addLayout(buttonLayout);
// preview pixmap
// prevMainLayout is here due the aligning with the others widgets
QHBoxLayout *prevMainLayout = new QHBoxLayout(0, 11, 6, "prevMainLayout");
QGroupBox *previewGBox = new QGroupBox(this, "previewGBox");
previewGBox->setTitle(tr("Preview"));
previewGBox->setColumnLayout(0, Qt::Vertical);
previewGBox->layout()->setSpacing(6);
previewGBox->layout()->setMargin(11);
QVBoxLayout *previewGBoxLayout = new QVBoxLayout(previewGBox->layout());
previewGBoxLayout->setAlignment(Qt::AlignTop);
previewLabel = new QLabel(previewGBox, "previewLabel");
previewGBoxLayout->addWidget(previewLabel);
prevMainLayout->addWidget(previewGBox);
guideManagerLayout->addLayout(mainWidgetsLayout);
guideManagerLayout->addLayout(prevMainLayout);
 
// set current guides
setGuidesFromList(horList, ScMW->doc->currentPage->YGuides);
setGuidesFromList(verList, ScMW->doc->currentPage->XGuides);
unitChange();
slotDrawPreview();
 
//tooltips
QToolTip::add( setButton, "<qt>" + tr("Set the guides in document. Guide manager is still opened but the changes are persistant", "guide manager") + "</qt>");
267,6 → 301,12
connect(verList, SIGNAL(currentChanged(QListViewItem*)), this, SLOT(verList_currentChanged(QListViewItem*)));
connect(useRowGap, SIGNAL(toggled(bool)), this, SLOT(useRowGap_clicked(bool)));
connect(useColGap, SIGNAL(toggled(bool)), this, SLOT(useColGap_clicked(bool)));
connect(this, SIGNAL(guidesChanged()), this, SLOT(slotDrawPreview()));
connect(rowSpin, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview()));
connect(colSpin, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview()));
connect(rowGap, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview()));
connect(colGap, SIGNAL(valueChanged(int)), this, SLOT(slotDrawPreview()));
connect(bGroup, SIGNAL(clicked(int)), this, SLOT(slotDrawPreview()));
}
 
GuideManager::~GuideManager()
274,12 → 314,12
ScMW->mainWindowStatusLabel->setText(QString::null);
}
 
void GuideManager::DelHorVal()
bool GuideManager::deleteValueFormList(QListView *list)
{
/* previous item pointer to ensure that ++it
runs before item goes deleted */
QListViewItem *itemToDelete;
QListViewItemIterator it(horList, QListViewItemIterator::Selected);
QListViewItemIterator it(list, QListViewItemIterator::Selected);
while (it.current())
{
itemToDelete = it.current();
286,26 → 326,22
++it;
if (itemToDelete)
{
horList->takeItem(itemToDelete);
list->takeItem(itemToDelete);
delete itemToDelete;
}
}
emit guidesChanged();
return true;
}
 
void GuideManager::DelHorVal()
{
deleteValueFormList(horList);
}
 
void GuideManager::DelVerVal()
{
QListViewItem *itemToDelete;
QListViewItemIterator it(verList, QListViewItemIterator::Selected);
while (it.current())
{
itemToDelete = it.current();
++it;
if (itemToDelete)
{
verList->takeItem(itemToDelete);
delete itemToDelete;
}
}
deleteValueFormList(verList);
}
 
bool GuideManager::addValueToList(QListView *list, MSpinBox *spin)
318,7 → 354,7
ScMW->mainWindowStatusLabel->setText(tr("There is empty (0.0) guide already"));
return false;
}
QListViewItem *item = new QListViewItem(list, tmp, suffix);
QListViewItem *item = new GuideListItem(list, tmp, suffix);
list->insertItem(item);
list->setCurrentItem(item);
list->clearSelection();
325,6 → 361,7
list->setSelected(item, true);
spin->setFocus();
spin->selectAll();
emit guidesChanged();
return true;
}
 
331,6 → 368,7
void GuideManager::AddHorVal()
{
addValueToList(horList, horSpin);
}
 
void GuideManager::AddVerVal()
400,8 → 438,14
 
void GuideManager::addRows()
{
if (allPages->isChecked() && rowSpin->value() > 0)
horList->clear();
setGuidesFromList(horList, getAutoRows());
}
 
QValueList<double> GuideManager::getAutoRows()
{
resetMarginsForPage();
horList->clear();
int n = QString(rowSpin->text()).toInt();
double offset = 0;
double newPageHeight = locPageHeight;
430,13 → 474,19
else
values.append(offset + (spacing * i));
}
setGuidesFromList(horList, values);
return values;
}
 
void GuideManager::addCols()
{
if (allPages->isChecked() && colSpin->value() > 0)
verList->clear();
setGuidesFromList(verList, getAutoCols());
}
 
QValueList<double> GuideManager::getAutoCols()
{
resetMarginsForPage();
verList->clear();
int n = QString(colSpin->text()).toInt();
double offset = 0;
double newPageWidth = locPageWidth;
465,7 → 515,7
else
values.append(offset + spacing * i);
}
setGuidesFromList(verList, values);
return values;
}
 
void GuideManager::ChangeHorVal()
476,6 → 526,7
QString tmp;
tmp = tmp.setNum(horSpin->value(), 'f', docUnitPrecision);
item->setText(0, tmp);
emit guidesChanged();
}
 
void GuideManager::ChangeVerVal()
486,6 → 537,7
QString tmp;
tmp = tmp.setNum(verSpin->value(), 'f', docUnitPrecision);
item->setText(0, tmp);
emit guidesChanged();
}
 
void GuideManager::unitChange()
565,11 → 617,15
for (it = guides.begin(); it != guides.end(); ++it)
{
tmp = tmp.setNum((*it) * docUnitRatio , 'f', docUnitPrecision);
QListViewItem *item = new QListViewItem(w, tmp, suffix);
// no insert for duplicates
if (w->findItem(tmp, 0) != 0)
continue;
QListViewItem *item = new GuideListItem(w, tmp, suffix);
w->insertItem(item);
}
w->setCurrentItem(w->firstChild());
w->setSelected(w->firstChild(), true);
emit guidesChanged();
}
 
QValueList<double> GuideManager::getValuesFromList(QListView *w)
593,6 → 649,7
else
val = item->text(0).toDouble();
verSpin->setValue(val);
emit guidesChanged();
}
 
void GuideManager::horList_currentChanged(QListViewItem *item)
603,4 → 660,59
else
val = item->text(0).toDouble();
horSpin->setValue(val);
emit guidesChanged();
}
 
void GuideManager::slotDrawPreview()
{
int size = 400; // height of the preview pixmap
int x, y; // helper values. original guide size to smaller one
double val; // position of the current guide (red one)
QPixmap pm; // paint device for preview
QPainter *p = new QPainter();
QValueList<double> vg = getValuesFromList(verList); // vert. g.
QValueList<double> hg = getValuesFromList(horList); // hor. g.
QValueList<double>::iterator it; // iterator for guides lists
 
vg += getAutoCols();
hg += getAutoRows();
//! \note Sorting is a must here for GUI
horList->sort();
verList->sort();
 
// load the page only at the first time
if (previewPixmap.isNull())
previewPixmap = ScMW->view->PageToPixmap(ScMW->doc->currentPageNumber(), size);
 
pm = previewPixmap;
p->begin(&pm);
p->setPen(QPen(ScMW->doc->guidesSettings.guideColor, 1, Qt::SolidLine));
// all guides - paint it standard
for (it = vg.begin(); it != vg.end(); ++it)
{
x = (int)(pm.width() * (*it) / ScMW->doc->currentPage->width());
p->drawLine(x, 0, x, pm.height());
}
for (it = hg.begin(); it != hg.end(); ++it)
{
y = (int)(pm.height() * (*it) / ScMW->doc->currentPage->height());
p->drawLine(0, y, pm.width(), y);
}
// current guide - paint it bold and red...
p->setPen(QPen(QColor(200, 0, 0), 3, Qt::SolidLine));
val = verSpin->value();
if (val > 0.0)
{
x = (int)(pm.width() * val / ScMW->doc->currentPage->width());
p->drawLine(x, 0, x, pm.height());
}
val = horSpin->value();
if (val > 0.0)
{
y = (int)(pm.height() * val / ScMW->doc->currentPage->height());
p->drawLine(0, y, pm.width(), y);
}
p->end();
previewLabel->setPixmap(pm);
delete p;
}
/branches/Version13x/Scribus/scribus/scribus.cpp
8129,7 → 8129,9
{
if (HaveDoc)
{
qApp->setOverrideCursor(QCursor(waitCursor), true);
GuideManager *dia = new GuideManager(this);
qApp->restoreOverrideCursor();
dia->exec();
delete dia;
}
/branches/Version13x/Scribus/scribus/guidemanager.h
1,13 → 1,12
#ifndef GUIDEMANAGER_H
#define GUIDEMANAGER_H
 
#include <qlistview.h>
#include "scribusapi.h"
#include "mspinbox.h"
 
class QWidget;
class QGroupBox;
class QListView;
class QListViewItem;
class QPushButton;
class QLabel;
class QString;
15,6 → 14,28
class QHButtonGroup;
 
 
/*! \brief Inherited QListViewItem provides double number values sorting.
Guides lists contains double values in 1st (0) columns. Standard QListViewItem
provides string sorting so I have to create some special number related one ;)
\author Petr Vanek <petr@yarpen.cz>
*/
class GuideListItem : public QListViewItem
{
public:
//! \brief Only 2 columns here...
GuideListItem(QListView *parent, QString c1, QString c2) : QListViewItem(parent, c1, c2){};
 
/*! \brief Reimplemented compare method to handle double values.
When is no double in column col parent string compare() is called.
\param i QListViewItem to compare with.
\param col column to sort (0 here)
\param asc ascendent on true.
\retval int -1 for (x lt y), 1 for (x gt y). See Qt docs for more info.
*/
int compare(QListViewItem *i, int col, bool asc) const;
};
 
 
/*! \brief \brief GuideManager is the dialog for guides managing ;).
Its public interface is used in scrubus.cpp
ScribusMainWindow::ManageGuides() via refreshDoc().
93,6 → 114,9
/*! \brief Apply selected guides on all pages */
QCheckBox* allPages;
 
//! \brief a pixmap preview holder
QLabel *previewLabel;
 
/*! \brief Gaps between guides.
User can create automatic guides with an optional two gapped instead one guide.
For example: 100mm size - guide - 100mm size will be 95mm size - guide - 10mm gap
112,6 → 136,12
//! \brief suffix of the unit [mm, ...]
QString suffix;
 
/*! \brief A preview page pixmap holder.
This pixmap is created only once - on the dialog opening.
It doesn't contain any guides on it. Guides are painted in
slotDrawPreview() on a copy of this pixmap. */
QPixmap previewPixmap;
 
/*! \brief Refresh the guides in the document while the dialog is still opened.
Or closed (of course). */
void refreshDoc();
144,6 → 174,29
*/
bool addValueToList(QListView *list, MSpinBox *spin);
 
/*! \brief Delete all selected values from list.
\param list a pointer to the chosen QListView
\retval bool false on error
*/
bool deleteValueFormList(QListView *list);
 
/*! \brief Create automatic horizontal guides.
Calculates positions of the guides.
This algorithm is used for guides creating and deleting too.
\retval QValueList<double> a list with guides */
QValueList<double> getAutoRows();
 
/*! \brief Create automatic vertical guides.
Calculates positions of the guides.
This algorithm is used for guides creating and deleting too.
\retval QValueList<double> a list with guides */
QValueList<double> getAutoCols();
 
signals:
/*! \brief Signal is emitt when the preview pixmap should be repainted.
*/
void guidesChanged();
 
protected slots:
 
/*! \brief delete horizontal value */
168,15 → 221,13
\param item current (new) item */
void horList_currentChanged(QListViewItem *item);
 
/*! \brief Create automatic vertical guides.
Calculates positions of the guides.
This algorithm is used for guides creating and deleting too.
/*! \brief Slot for automatic rows calling
See getAutoRows()
*/
void addRows();
 
/*! \brief Create automatic horizontal guides.
Calculates positions of the guides.
This algorithm is used for guides creating and deleting too.
/*! \brief Slot for automatic columns calling
See getAutoCols()
*/
void addCols();
 
193,6 → 244,13
 
/*! \brief Commits all chasnges and keep the dialog open */
void commitEditChanges();
 
/*! \brief Sorts the lists and create page-with-guides preview pixmap.
This slot takes pixmap stored in previewPixmap each time
it's called. The guides are painted on the copy of pre-created
pixmap. Common guides are painted with black; currently selected
guide is painded dark red and ticker. */
void slotDrawPreview();
};
 
#endif // GUIDEMANAGER_H