add edit image to context menu

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@2508 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2013-09-10 14:44:25 +00:00
parent 95a399c2b7
commit 7cfb83d350
5 changed files with 123 additions and 72 deletions

View File

@@ -111,55 +111,7 @@ void DiagramImageItem::mousePressEvent(QGraphicsSceneMouseEvent *e) {
*/
void DiagramImageItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) {
Q_UNUSED (event);
if (diagram() -> isReadOnly()) return;
//the range for scale image and divisor factor
int min_range = 1;
int max_range = 200;
int factor_range = 100;
//the dialog
QDialog property_dialog;
property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
//the main layout
QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
//GroupBox for resizer image
QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
dialog_layout -> addWidget(resize_groupe);
QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
//slider
QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
slider->setRange(min_range, max_range);
qreal scale_= scale();
slider -> setValue(scale_*factor_range);
//spinbox
QSpinBox *spin_box = new QSpinBox(&property_dialog);
spin_box -> setRange(min_range, max_range);
spin_box -> setValue(scale_*factor_range);
spin_box -> setSuffix(" %");
//synchro slider with spinbox
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
//add slider and spinbox to layout
resize_layout -> addWidget(slider);
resize_layout -> addWidget(spin_box);
//dialog button, box
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dbb);
connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
//dialog is accepted...
if (property_dialog.exec() == QDialog::Accepted) {
qreal new_scale = slider -> value();
new_scale /= factor_range;
if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
}
//...or not
else setScale(scale_);
return;
edit();
}
/**
@@ -266,7 +218,55 @@ void DiagramImageItem::PreviewScale(int scale) {
* @brief Edit the image with ....
*/
void DiagramImageItem::edit() {
// waiting
if (diagram() -> isReadOnly()) return;
//the range for scale image and divisor factor
int min_range = 1;
int max_range = 200;
int factor_range = 100;
//the dialog
QDialog property_dialog;
property_dialog.setWindowTitle(tr("\311diter les propri\351t\351s d'une image", "window title"));
//the main layout
QVBoxLayout *dialog_layout = new QVBoxLayout(&property_dialog);
//GroupBox for resizer image
QGroupBox *resize_groupe = new QGroupBox(tr("Dimension de l'image", "image size"));
dialog_layout -> addWidget(resize_groupe);
QHBoxLayout *resize_layout = new QHBoxLayout(resize_groupe);
//slider
QSlider *slider = new QSlider(Qt::Horizontal, &property_dialog);
slider->setRange(min_range, max_range);
qreal scale_= scale();
slider -> setValue(scale_*factor_range);
//spinbox
QSpinBox *spin_box = new QSpinBox(&property_dialog);
spin_box -> setRange(min_range, max_range);
spin_box -> setValue(scale_*factor_range);
spin_box -> setSuffix(" %");
//synchro slider with spinbox
connect(slider, SIGNAL(valueChanged(int)), spin_box, SLOT(setValue(int)));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(PreviewScale(int)));
connect(spin_box, SIGNAL(valueChanged(int)), slider, SLOT(setValue(int)));
//add slider and spinbox to layout
resize_layout -> addWidget(slider);
resize_layout -> addWidget(spin_box);
//dialog button, box
QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
dialog_layout -> addWidget(dbb);
connect(dbb, SIGNAL(accepted()), &property_dialog, SLOT(accept()));
connect(dbb, SIGNAL(rejected()), &property_dialog, SLOT(reject()));
//dialog is accepted...
if (property_dialog.exec() == QDialog::Accepted) {
qreal new_scale = slider -> value();
new_scale /= factor_range;
if (scale_ != new_scale) diagram()->undoStack().push(new ImageResizerCommand(this, scale_, new_scale));
}
//...or not
else setScale(scale_);
return;
}
void DiagramImageItem::setPixmap(const QPixmap &pixmap) {