void NBaseImageCropper::setOOProportion() { if(!isOOFixed){ ooBtn->setStyleSheet(tr("QPushButton[ooBtn=\"true\"]{border-image:url(:lock_t);color:#e8853b;}" "QPushButton[ooBtn=\"true\"]:hover{border-image:url(:bright);color:#e8853b;}")); setProportion(1,1); isOOFixed = true; } else { setNoProportion(); isOOFixed = false; } }
void MobilityDiagram::mouseMoveEvent(QMouseEvent *event) { if (!event || !_isDraging || !_isPointInDiagram(event->pos())) { _isDraging = false; return; } const double size = _dimension.width() / 2; const double x = event->pos().x() - size, y = size - event->pos().y(); double alpha; _previousPoint = _currentPoint; double X1 = _previousPoint.x(); double Y1 = _previousPoint.y(); _currentPoint.rx() = x; _currentPoint.ry() = y; double X2 = _currentPoint.x(); double Y2 = _currentPoint.y(); if (X1 == 0.0f) X1 = 0.001f; if (X2 == 0.0f) X2 = 0.001f; double alpha1 = atan(Y1 / X1); double alpha2 = atan(Y2 / X2); alpha = alpha2 - alpha1; if (alpha > PI2) alpha -= PI; else if (alpha < -PI2) alpha += PI; double result = _proportions.value(_dragedMean) - (alpha * 180. / PI) * (1 - 2 * (!_dragedMean)); setProportion(_dragedMean, result); update(); }
void ContactAvatarWidget::cropAvatar() { QWidget *hostWidget = nullptr; QLayout *hostLayout = nullptr; QWidget *mainWidget = nullptr; QLayout *mainLayout = nullptr; if (imageCropHolder_) { hostWidget = new QWidget(this); hostLayout = new QHBoxLayout(hostWidget); hostWidget->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Fixed); hostWidget->setFixedHeight(imageCropSize_.height()); hostLayout->setContentsMargins(Utils::scale_value(16), Utils::scale_value(12), Utils::scale_value(16), 0); mainWidget = new QWidget(hostWidget); mainLayout = Utils::emptyHLayout(mainWidget); mainWidget->setSizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred); hostLayout->addWidget(mainWidget); } else { mainWidget = new QWidget(this); mainLayout = new QHBoxLayout(mainWidget); mainLayout->setContentsMargins(Utils::scale_value(16), Utils::scale_value(12), Utils::scale_value(16), 0); } auto avatarCropper = new Ui::ImageCropper(mainWidget, imageCropSize_); avatarCropper->setProportion(QSizeF(1.0, 1.0)); avatarCropper->setProportionFixed(true); avatarCropper->setBackgroundColor(CommonStyle::getFrameColor()); if (!infoForSetAvatar_.croppingRect.isNull()) { avatarCropper->setCroppingRect(infoForSetAvatar_.croppingRect); } avatarCropper->setImage(QPixmap::fromImage(infoForSetAvatar_.image)); mainLayout->addWidget(avatarCropper); if (!imageCropHolder_) { hostWidget = mainWidget; } GeneralDialog imageCropDialog(hostWidget, imageCropHolder_ ? imageCropHolder_ : Utils::InterConnector::instance().getMainWindow()); imageCropDialog.setObjectName(qsl("image.cropper")); if (imageCropHolder_) { imageCropDialog.setShadow(false); imageCropDialog.connect(&imageCropDialog, &GeneralDialog::moved, this, [=](QWidget *dlg) { emit Utils::InterConnector::instance().imageCropDialogMoved(dlg); }); imageCropDialog.connect(&imageCropDialog, &GeneralDialog::resized, this, [=](QWidget *dlg) { emit Utils::InterConnector::instance().imageCropDialogResized(dlg); }); imageCropDialog.connect(&imageCropDialog, &GeneralDialog::shown, this, [=](QWidget *dlg) { emit Utils::InterConnector::instance().imageCropDialogIsShown(dlg); }); imageCropDialog.connect(&imageCropDialog, &GeneralDialog::hidden, this, [=](QWidget *dlg) { emit Utils::InterConnector::instance().imageCropDialogIsHidden(dlg); }); } imageCropDialog.addHead(); imageCropDialog.addLabel(mode_ == Mode::CreateChat ? QT_TRANSLATE_NOOP("avatar_upload", "Edit photo") : QT_TRANSLATE_NOOP("avatar_upload", "Upload photo")); imageCropDialog.addButtonsPair(QT_TRANSLATE_NOOP("popup_window", "BACK"), QT_TRANSLATE_NOOP("popup_window", "CONTINUE"), true, false, false); imageCropDialog.setRightButtonDisableOnClicked(true); QObject::connect(&imageCropDialog, &GeneralDialog::leftButtonClicked, this, [=, &imageCropDialog]() { imageCropDialog.reject(); QTimer::singleShot(500, this, [=](){ emit summonSelectFileForAvatar(); }); }, Qt::QueuedConnection); QObject::connect(&imageCropDialog, &GeneralDialog::rightButtonClicked, this, [=, &imageCropDialog]() { auto croppedImage = avatarCropper->cropImage(); auto croppingRect = avatarCropper->getCroppingRect(); infoForSetAvatar_.croppedImage = croppedImage; infoForSetAvatar_.croppingRect = croppingRect; imageCropDialog.accept(); if (auto p = imageCropDialog.takeAcceptButton()) p->setEnabled(true); }, Qt::QueuedConnection); QObject::connect(&imageCropDialog, &GeneralDialog::shown, this, [=](QWidget *dlg) { // }, Qt::QueuedConnection); if (!imageCropDialog.showInPosition(-1, -1)) { return; } if (mode_ == Mode::CreateChat) { infoForSetAvatar_.roundedCroppedImage = QPixmap(); emit avatarDidEdit(); } else { openAvatarPreview(); } }