Changeset View
Changeset View
Standalone View
Standalone View
libs/ui/widgets/KoFillConfigWidget.cpp
| Context not available. | |||||
| 178 | : canvas(0), | 178 | : canvas(0), | ||
|---|---|---|---|---|---|
| 179 | colorChangedCompressor(100, KisSignalCompressor::FIRST_ACTIVE), | 179 | colorChangedCompressor(100, KisSignalCompressor::FIRST_ACTIVE), | ||
| 180 | gradientChangedCompressor(100, KisSignalCompressor::FIRST_ACTIVE), | 180 | gradientChangedCompressor(100, KisSignalCompressor::FIRST_ACTIVE), | ||
| 181 | shapeChangedCompressor(200,KisSignalCompressor::FIRST_ACTIVE), | ||||
| 181 | fillVariant(_fillVariant), | 182 | fillVariant(_fillVariant), | ||
| 182 | noSelectionTrackingMode(false) | 183 | noSelectionTrackingMode(false) | ||
| 183 | { | 184 | { | ||
| Context not available. | |||||
| 197 | 198 | | |||
| 198 | QSharedPointer<KoStopGradient> activeGradient; | 199 | QSharedPointer<KoStopGradient> activeGradient; | ||
| 199 | KisSignalCompressor gradientChangedCompressor; | 200 | KisSignalCompressor gradientChangedCompressor; | ||
| 201 | KisSignalCompressor shapeChangedCompressor; | ||||
| 200 | KoFlake::FillVariant fillVariant; | 202 | KoFlake::FillVariant fillVariant; | ||
| 201 | 203 | | |||
| 204 | | ||||
| 205 | QList<KoShape*> previousShapeSelected;/// container to see if the selection has actually changed | ||||
| 206 | | ||||
| 202 | bool noSelectionTrackingMode; | 207 | bool noSelectionTrackingMode; | ||
| 203 | 208 | | |||
| 204 | Ui_KoFillConfigWidget *ui; | 209 | Ui_KoFillConfigWidget *ui; | ||
| Context not available. | |||||
| 215 | if (trackShapeSelection) { | 220 | if (trackShapeSelection) { | ||
| 216 | d->shapeChangedAcyclicConnector.connectBackwardVoid( | 221 | d->shapeChangedAcyclicConnector.connectBackwardVoid( | ||
| 217 | d->canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), | 222 | d->canvas->selectedShapesProxy(), SIGNAL(selectionChanged()), | ||
| 218 | this, SLOT(shapeChanged())); | 223 | &d->shapeChangedCompressor, SLOT(start())); | ||
| 219 | 224 | | |||
| 220 | d->shapeChangedAcyclicConnector.connectBackwardVoid( | 225 | d->shapeChangedAcyclicConnector.connectBackwardVoid( | ||
| 221 | d->canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), | 226 | d->canvas->selectedShapesProxy(), SIGNAL(selectionContentChanged()), | ||
| 222 | this, SLOT(shapeChanged())); | 227 | &d->shapeChangedCompressor, SLOT(start())); | ||
| 228 | | ||||
| 229 | | ||||
| 230 | connect(&d->shapeChangedCompressor, SIGNAL(timeout()), this, SLOT(shapeChanged())); | ||||
| 231 | | ||||
| 223 | } | 232 | } | ||
| 224 | 233 | | |||
| 225 | d->resourceManagerAcyclicConnector.connectBackwardResourcePair( | 234 | d->resourceManagerAcyclicConnector.connectBackwardResourcePair( | ||
| Context not available. | |||||
| 328 | d->deactivationLocks.clear(); | 337 | d->deactivationLocks.clear(); | ||
| 329 | 338 | | |||
| 330 | if (!d->noSelectionTrackingMode) { | 339 | if (!d->noSelectionTrackingMode) { | ||
| 331 | shapeChanged(); | 340 | d->shapeChangedCompressor.start(); | ||
| 332 | } else { | 341 | } else { | ||
| 333 | loadCurrentFillFromResourceServer(); | 342 | loadCurrentFillFromResourceServer(); | ||
| 334 | } | 343 | } | ||
| Context not available. | |||||
| 345 | 354 | | |||
| 346 | void KoFillConfigWidget::forceUpdateOnSelectionChanged() | 355 | void KoFillConfigWidget::forceUpdateOnSelectionChanged() | ||
| 347 | { | 356 | { | ||
| 348 | shapeChanged(); | 357 | d->shapeChangedCompressor.start(); | ||
| 349 | } | 358 | } | ||
| 350 | 359 | | |||
| 351 | void KoFillConfigWidget::setNoSelectionTrackingMode(bool value) | 360 | void KoFillConfigWidget::setNoSelectionTrackingMode(bool value) | ||
| 352 | { | 361 | { | ||
| 353 | d->noSelectionTrackingMode = value; | 362 | d->noSelectionTrackingMode = value; | ||
| 354 | if (!d->noSelectionTrackingMode) { | 363 | if (!d->noSelectionTrackingMode) { | ||
| 355 | shapeChanged(); | 364 | d->shapeChangedCompressor.start(); | ||
| 356 | } | 365 | } | ||
| 357 | } | 366 | } | ||
| 358 | 367 | | |||
| Context not available. | |||||
| 477 | d->canvas->addCommand(command); | 486 | d->canvas->addCommand(command); | ||
| 478 | } | 487 | } | ||
| 479 | 488 | | |||
| 489 | | ||||
| 490 | if (d->fillVariant == KoFlake::StrokeFill) { | ||||
| 491 | KUndo2Command *lineCommand = wrapper.setLineWidth(0.0); | ||||
| 492 | if (lineCommand) { | ||||
| 493 | d->canvas->addCommand(lineCommand); | ||||
| 494 | } | ||||
| 495 | } | ||||
| 496 | | ||||
| 497 | | ||||
| 480 | emit sigFillChanged(); | 498 | emit sigFillChanged(); | ||
| 481 | } | 499 | } | ||
| 482 | 500 | | |||
| Context not available. | |||||
| 722 | 740 | | |||
| 723 | QList<KoShape*> shapes = currentShapes(); | 741 | QList<KoShape*> shapes = currentShapes(); | ||
| 724 | 742 | | |||
| 743 | // check to see if the shape actually changed...or is still the same shape | ||||
| 744 | if (d->previousShapeSelected == shapes) { | ||||
| 745 | return; | ||||
| 746 | } else { | ||||
| 747 | d->previousShapeSelected = shapes; | ||||
| 748 | } | ||||
| 749 | | ||||
| 750 | | ||||
| 725 | if (shapes.isEmpty() || | 751 | if (shapes.isEmpty() || | ||
| 726 | (shapes.size() > 1 && KoShapeFillWrapper(shapes, d->fillVariant).isMixedFill())) { | 752 | (shapes.size() > 1 && KoShapeFillWrapper(shapes, d->fillVariant).isMixedFill())) { | ||
| 727 | 753 | | |||
| 728 | Q_FOREACH (QAbstractButton *button, d->group->buttons()) { | 754 | Q_FOREACH (QAbstractButton *button, d->group->buttons()) { | ||
| 729 | button->setEnabled(!shapes.isEmpty()); | 755 | button->setEnabled(!shapes.isEmpty()); | ||
| 730 | } | 756 | } | ||
| 731 | | ||||
| 732 | d->group->button(None)->setChecked(true); | | |||
| 733 | d->selectedFillIndex = None; | | |||
| 734 | | ||||
| 735 | } else { | 757 | } else { | ||
| 758 | // only one vector object selected | ||||
| 736 | Q_FOREACH (QAbstractButton *button, d->group->buttons()) { | 759 | Q_FOREACH (QAbstractButton *button, d->group->buttons()) { | ||
| 737 | button->setEnabled(true); | 760 | button->setEnabled(true); | ||
| 738 | } | 761 | } | ||
| 739 | 762 | | |||
| 763 | // update active index of shape | ||||
| 740 | KoShape *shape = shapes.first(); | 764 | KoShape *shape = shapes.first(); | ||
| 741 | updateWidget(shape); | 765 | updateFillIndexFromShape(shape); | ||
| 742 | } | 766 | } | ||
| 743 | } | | |||
| 744 | 767 | | |||
| 745 | bool KoFillConfigWidget::checkNewFillModeIsSame(const KoShapeFillWrapper &w) const | | |||
| 746 | { | | |||
| 747 | bool retval = false; | | |||
| 748 | 768 | | |||
| 749 | switch (w.type()) { | 769 | // updates the UI | ||
| 750 | case KoFlake::None: | 770 | d->group->button(d->selectedFillIndex)->setChecked(true); | ||
| 751 | retval = d->selectedFillIndex == None; | 771 | styleButtonPressed(d->selectedFillIndex); | ||
| 752 | break; | 772 | slotUpdateFillTitle(); | ||
| 753 | case KoFlake::Solid: | 773 | updateWidgetComponentVisbility(); | ||
| 754 | retval = d->selectedFillIndex == Solid && w.color() == d->colorAction->currentColor(); | | |||
| 755 | break; | | |||
| 756 | case KoFlake::Gradient: { | | |||
| 757 | QScopedPointer<KoStopGradient> newGradient(KoStopGradient::fromQGradient(w.gradient())); | | |||
| 758 | | ||||
| 759 | retval = d->selectedFillIndex == Gradient && *newGradient == *d->activeGradient; | | |||
| 760 | break; | | |||
| 761 | } | | |||
| 762 | case KoFlake::Pattern: | | |||
| 763 | // TODO: not implemented | | |||
| 764 | retval = d->selectedFillIndex == Pattern && false; | | |||
| 765 | break; | | |||
| 766 | } | | |||
| 767 | 774 | | |||
| 768 | return retval; | | |||
| 769 | } | 775 | } | ||
| 770 | 776 | | |||
| 771 | void KoFillConfigWidget::updateWidget(KoShape *shape) | 777 | void KoFillConfigWidget::updateFillIndexFromShape(KoShape *shape) | ||
| 772 | { | 778 | { | ||
| 773 | KIS_SAFE_ASSERT_RECOVER_RETURN(shape); | 779 | KIS_SAFE_ASSERT_RECOVER_RETURN(shape); | ||
| 774 | 780 | | |||
| 775 | StyleButton newActiveButton = None; | | |||
| 776 | KoShapeFillWrapper wrapper(shape, d->fillVariant); | 781 | KoShapeFillWrapper wrapper(shape, d->fillVariant); | ||
| 777 | 782 | | |||
| 778 | if (checkNewFillModeIsSame(wrapper)) return; | | |||
| 779 | | ||||
| 780 | switch (wrapper.type()) { | 783 | switch (wrapper.type()) { | ||
| 781 | case KoFlake::None: | 784 | case KoFlake::None: | ||
| 782 | break; | 785 | d->selectedFillIndex = KoFillConfigWidget::None; | ||
| 783 | case KoFlake::Solid: { | 786 | break; | ||
| 784 | QColor color = wrapper.color(); | 787 | case KoFlake::Solid: { | ||
| 785 | if (color.alpha() > 0) { | 788 | d->selectedFillIndex = KoFillConfigWidget::Solid; | ||
| 786 | newActiveButton = KoFillConfigWidget::Solid; | 789 | QColor color = wrapper.color(); | ||
| 787 | d->colorAction->setCurrentColor(wrapper.color()); | 790 | if (color.alpha() > 0) { | ||
| 791 | d->colorAction->setCurrentColor(wrapper.color()); | ||||
| 792 | } | ||||
| 793 | break; | ||||
| 788 | } | 794 | } | ||
| 789 | break; | 795 | case KoFlake::Gradient: | ||
| 790 | } | 796 | d->selectedFillIndex = KoFillConfigWidget::Gradient; | ||
| 791 | case KoFlake::Gradient: | 797 | uploadNewGradientBackground(wrapper.gradient()); | ||
| 792 | newActiveButton = KoFillConfigWidget::Gradient; | 798 | updateGradientSaveButtonAvailability(); | ||
| 793 | uploadNewGradientBackground(wrapper.gradient()); | 799 | break; | ||
| 794 | updateGradientSaveButtonAvailability(); | 800 | case KoFlake::Pattern: | ||
| 795 | break; | 801 | d->selectedFillIndex = KoFillConfigWidget::Pattern; | ||
| 796 | case KoFlake::Pattern: | 802 | break; | ||
| 797 | newActiveButton = KoFillConfigWidget::Pattern; | | |||
| 798 | break; | | |||
| 799 | } | 803 | } | ||
| 800 | 804 | | |||
| 801 | d->group->button(newActiveButton)->setChecked(true); | | |||
| 802 | | ||||
| 803 | d->selectedFillIndex = newActiveButton; | | |||
| 804 | updateWidgetComponentVisbility(); | | |||
| 805 | } | 805 | } | ||
| 806 | 806 | | |||
| 807 | 807 | | |||
| Context not available. | |||||
| 824 | d->ui->soldStrokeColorLabel->setVisible(false); | 824 | d->ui->soldStrokeColorLabel->setVisible(false); | ||
| 825 | d->ui->presetLabel->setVisible(false); | 825 | d->ui->presetLabel->setVisible(false); | ||
| 826 | 826 | | |||
| 827 | // keep options hidden if no vector shapes are selected | ||||
| 828 | if(currentShapes().isEmpty()) { | ||||
| 829 | return; | ||||
| 830 | } | ||||
| 831 | | ||||
| 827 | switch (d->selectedFillIndex) { | 832 | switch (d->selectedFillIndex) { | ||
| 828 | case KoFillConfigWidget::None: | 833 | case KoFillConfigWidget::None: | ||
| 829 | break; | 834 | break; | ||
| Context not available. | |||||