原来点击按钮裁剪一次,4个边要来回编辑数量点击按钮。
改成4个QSpinbox + 确定,算好数值,只需要1次就可以裁剪4个边。
void MainWindow::on_action_cutBorder_triggered()
{
QDialog *dialog = new QDialog(this);
dialog->setWindowTitle("边缘裁剪");
dialog->setFixedSize(200, 150);
QVBoxLayout *vbox = new QVBoxLayout;
QGridLayout *gridLayout = new QGridLayout;
int rx = imageWidget->image.width() / 3;
int ry = imageWidget->image.height() / 3;
QSpinBox *spinBox_top = new QSpinBox;
spinBox_top->setValue(0);
spinBox_top->setRange(0, ry);
gridLayout->addWidget(spinBox_top, 0, 1);
QSpinBox *spinBox_left = new QSpinBox;
spinBox_left->setValue(0);
spinBox_left->setRange(0, rx);
gridLayout->addWidget(spinBox_left, 1, 0);
QSpinBox *spinBox_right = new QSpinBox;
spinBox_right->setValue(0);
spinBox_right->setRange(0, rx);
gridLayout->addWidget(spinBox_right, 1, 2);
QSpinBox *spinBox_bottom = new QSpinBox;
spinBox_bottom->setValue(0);
spinBox_bottom->setRange(0, ry);
gridLayout->addWidget(spinBox_bottom, 2, 1);
vbox->addLayout(gridLayout);
QPushButton *pushButton_confirm = new QPushButton("确定");
QPushButton *pushButton_cancel = new QPushButton("取消");
QHBoxLayout *hbox = new QHBoxLayout;
hbox->addStretch();
hbox->addWidget(pushButton_confirm);
hbox->addWidget(pushButton_cancel);
hbox->addStretch();
vbox->addLayout(hbox);
dialog->setLayout(vbox);
connect(pushButton_confirm, SIGNAL(clicked()), dialog, SLOT(accept()));
connect(pushButton_cancel, SIGNAL(clicked()), dialog, SLOT(reject()));
if (dialog->exec() == QDialog::Accepted) {
imageWidget->cutBorder(spinBox_top->value(), spinBox_right->value(), spinBox_bottom->value(), spinBox_left->value());
}
}
void ImageWidget::cutBorder(int top, int right, int bottom, int left)
{
image = image.copy(left, top, image.width() - left - right, image.height() - top - bottom);
imgtemp = image;
update();
}