13#include <QApplication>
15#include <QDialogButtonBox>
23#include <kstandardguiitem.h>
53 static QString str = i18n(
"Pixels/Inch");
59 static QString str = i18n(
"Pixels/Centimeter");
65 , m_dialogType(dialogType)
67 setObjectName(
"KisCustomImageWidget");
68 m_openPane = qobject_cast<KisOpenPane*>(parent);
80 txtName->setText(imageName);
82 doubleWidth->setValue(defWidth);
83 doubleWidth->setDecimals(0);
89 doubleHeight->setValue(defHeight);
90 doubleHeight->setDecimals(0);
98 doubleResolution->setValue(72.0 * resolution);
99 doubleResolution->setDecimals(2);
101 grpClipboard->hide();
103 sliderOpacity->setRange(0, 100, 0);
104 sliderOpacity->setValue(100);
108 connect(doubleResolution, SIGNAL(valueChanged(
double)),
110 connect(cmbWidthUnit, SIGNAL(activated(
int)),
112 connect(doubleWidth, SIGNAL(valueChanged(
double)),
114 connect(cmbHeightUnit, SIGNAL(activated(
int)),
116 connect(doubleHeight, SIGNAL(valueChanged(
double)),
118 connect(cmbResolutionUnit, SIGNAL(currentIndexChanged(
int)),
123 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setText(i18n(
"&Create"));
124 KGuiItem::assign(newDialogConfirmationButtonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
125 connect(newDialogConfirmationButtonBox, SIGNAL(accepted()),
this, SLOT(
createImage()));
129 connect(newDialogConfirmationButtonBox, SIGNAL(rejected()),
m_openPane, SLOT(reject()));
134 connect(bnPortrait, SIGNAL(clicked()), SLOT(
setPortrait()));
135 connect(bnLandscape, SIGNAL(clicked()), SLOT(
setLandscape()));
140 connect(bnSaveAsPredefined, SIGNAL(clicked()),
this, SLOT(
saveAsPredefined()));
142 colorSpaceSelector->setCurrentColorModel(
KoID(defColorModel));
143 colorSpaceSelector->setCurrentColorDepth(
KoID(defColorDepth));
144 colorSpaceSelector->setCurrentProfile(defColorProfile);
147 connect(colorSpaceSelector, SIGNAL(selectionChanged(
bool)), newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok), SLOT(setEnabled(
bool)));
152 cmbColor->setColor(bcol);
158 radioBackgroundAsRaster->setChecked(
true);
160 radioBackgroundAsFill->setChecked(
true);
162 radioBackgroundAsProjection->setChecked(
true);
170 QPalette
p = QApplication::palette();
171 QPalette palette_highlight(
p );
172 QColor c =
p.color(QPalette::Highlight);
173 palette_highlight.setColor(QPalette::Button, c);
174 bnLandscape->setPalette(palette_highlight);
175 bnPortrait->setPalette(palette_highlight);
182 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setFocus();
183 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
207 qreal resolution = doubleResolution->value();
217 doubleResolution->setValue(resolution);
223 doubleWidth->blockSignals(
true);
227 doubleWidth->setDecimals(0);
230 doubleWidth->setDecimals(2);
235 doubleWidth->blockSignals(
false);
247 doubleHeight->blockSignals(
true);
251 doubleHeight->setDecimals(0);
254 doubleHeight->setDecimals(2);
259 doubleHeight->blockSignals(
false);
271 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
278 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
284 const KoColorSpace * cs = colorSpaceSelector->currentColorSpace();
291 if (profile->
name().contains(
"linear") ||
292 profile->
name().contains(
"scRGB") ||
293 profile->
info().contains(
"linear") ||
294 profile->
info().contains(
"scRGB")) {
297 QMessageBox::warning(
this,
298 i18nc(
"@title:window",
"Krita"),
299 i18n(
"Linear gamma RGB color spaces are not supposed to be used "
300 "in 8-bit integer modes. It is suggested to use 16-bit integer "
301 "or any floating point colorspace for linear profiles.\n\n"
302 "Press \"Ok\" to create a 8-bit integer linear RGB color space "
303 "or \"Cancel\" to return to the settings dialog."),
304 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
306 if (result == QMessageBox::Cancel) {
307 dbgKrita <<
"Model RGB8" <<
"NOT SUPPORTED";
317 qint32 width, height;
321 resolution = doubleResolution->value() / 72.0;
323 resolution = doubleResolution->value() / 28.34;
330 QColor qc = cmbColor->color().toQColor();
335 if( radioBackgroundAsRaster->isChecked() ){
337 }
else if( radioBackgroundAsFill->isChecked() ){
341 doc->
newImage(txtName->text(), width, height, cs, bgColor, bgStyle, intNumLayers->value(), txtDescription->toPlainText(), resolution);
370 intNumLayers->setValue(layers);
375 qint32 opacity = sliderOpacity->value();
380 return (opacity * 255) / 100;
384 sliderOpacity->setValue((
value * 100) / 255);
389 cmbPredefined->clear();
392 cmbPredefined->addItem(
"");
397 if (!definitions.empty()) {
399 Q_FOREACH (
const QString &definition, definitions) {
401 if (f.open(QIODevice::ReadOnly)) {
402 QString xml = QString::fromUtf8(f.readAll());
404 predefined->fromXML(xml);
405 if (predefined->hasProperty(
"name")
406 && predefined->hasProperty(
"width")
407 && predefined->hasProperty(
"height")
408 && predefined->hasProperty(
"resolution")
409 && predefined->hasProperty(
"x-unit")
410 && predefined->hasProperty(
"y-unit")) {
412 cmbPredefined->addItem(predefined->getString(
"name"));
418 cmbPredefined->setCurrentIndex(0);
428 txtPredefinedName->setText(predefined->getString(
"name"));
430 doubleResolution->setValue(predefined->getDouble(
"resolution"));
434 cmbWidthUnit->setCurrentIndex(predefined->getInt(
"x-unit"));
435 cmbHeightUnit->setCurrentIndex(predefined->getInt(
"y-unit"));
440 doubleWidth->setValue(predefined->getDouble(
"width"));
441 doubleHeight->setValue(predefined->getDouble(
"height"));
448 QString fileName = txtPredefinedName->text();
449 if (fileName.isEmpty()) {
453 QFile f(saveLocation +
'/' + fileName.replace(
' ',
'_').replace(
'(',
'_').replace(
')',
'_').replace(
':',
'_') +
".predefinedimage");
455 if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
456 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"),
457 i18n(
"Could not save %1.\nReason: %2.", f.fileName(), f.errorString()));
461 predefined->setProperty(
"name", txtPredefinedName->text());
462 predefined->setProperty(
"width", doubleWidth->value());
463 predefined->setProperty(
"height", doubleHeight->value());
464 predefined->setProperty(
"resolution", doubleResolution->value());
465 predefined->setProperty(
"x-unit", cmbWidthUnit->currentIndex());
466 predefined->setProperty(
"y-unit", cmbHeightUnit->currentIndex());
468 QString xml = predefined->toXML();
470 f.write(xml.toUtf8());
477 if (pr->getString(
"name") == txtPredefinedName->text()) {
488 cmbPredefined->addItem(txtPredefinedName->text());
495 if (doubleWidth->value() < doubleHeight->value()) {
502 if (doubleWidth->value() > doubleHeight->value()) {
509 double width = doubleWidth->value();
510 double height = doubleHeight->value();
512 doubleHeight->clearFocus();
513 doubleWidth->clearFocus();
515 doubleHeight->blockSignals(
true);
516 doubleWidth->blockSignals(
true);
517 cmbWidthUnit->blockSignals(
true);
518 cmbHeightUnit->blockSignals(
true);
520 doubleWidth->setValue(height);
521 doubleHeight->setValue(width);
525 doubleHeight->blockSignals(
false);
526 doubleWidth->blockSignals(
false);
527 cmbWidthUnit->blockSignals(
false);
528 cmbHeightUnit->blockSignals(
false);
538 if(doubleWidth->value() > doubleHeight->value())
539 bnLandscape->setChecked(
true);
541 bnPortrait->setChecked(
true);
547 qint64 width, height;
549 resolution = doubleResolution->value() / 72.0;
554 qint64 layerSize = width * height;
555 const KoColorSpace *cs = colorSpaceSelector->currentColorSpace();
558 QString text = i18nc(
"arg1: width. arg2: height. arg3: colorspace name. arg4: size of a channel in bits. arg5: image size",
559 "This document will be %1 pixels by %2 pixels in %3. The pixel size is %4 bit. A single paint layer will use %5 of RAM.",
564 KFormat().formatByteSize(layerSize));
565 lblDocumentInfo->setText(text);
float value(const T *src, size_t ch)
const KoID Integer8BitsColorDepthID("U8", ki18n("8-bit integer/channel"))
const KoID RGBAColorModelID("RGBA", ki18n("RGB/Alpha"))
void setDefaultBackgroundOpacity(const QLatin1String &dialogType, quint8 value)
qint32 defImageHeight(bool defaultValue=false) const
void setDefaultBackgroundStyle(const QLatin1String &dialogType, BackgroundStyle value)
qint32 defImageWidth(bool defaultValue=false) const
BackgroundStyle defaultBackgroundStyle(const QLatin1String &dialogType, bool defaultValue=false) const
QColor defaultBackgroundColor(const QLatin1String &dialogType, bool defaultValue=false) const
void setDefaultBackgroundColor(const QLatin1String &dialogType, const QColor &value)
bool useDefaultColorSpace(bool defaultvalue=false) const
quint8 defaultBackgroundOpacity(const QLatin1String &dialogType, bool defaultValue=false) const
void setDefaultColorDepth(const QString &depth) const
qreal defImageResolution(bool defaultValue=false) const
int numDefaultLayers(const QLatin1String &dialogType, bool defaultValue=false) const
void setNumDefaultLayers(const QLatin1String &dialogType, int num)
QString defColorProfile(bool defaultValue=false) const
QString defColorModel(bool defaultValue=false) const
QString defaultColorDepth(bool defaultValue=false) const
void setModified(bool _mod)
bool newImage(const QString &name, qint32 width, qint32 height, const KoColorSpace *cs, const KoColor &bgColor, KisConfig::BackgroundStyle bgStyle, int numberOfLayers, const QString &imageDescription, const double imageResolution)
void documentSelected(KisDocument *)
this signal is emitted (as defined by KisDocument) the moment the document is 'ready'
static KisPart * instance()
KisDocument * createDocument() const
virtual quint32 pixelSize() const =0
virtual KoID colorModelId() const =0
virtual KoID colorDepthId() const =0
virtual const KoColorProfile * profile() const =0
void fromQColor(const QColor &c)
Convenient function for converting from a QColor.
static QStringList findAllAssets(const QString &type, const QString &filter=QString(), SearchOptions options=NoSearchOptions)
static QString saveLocation(const QString &type, const QString &suffix=QString(), bool create=true)
static qreal convertFromUnitToUnit(const qreal value, const KoUnit &fromUnit, const KoUnit &toUnit, qreal factor=1.0)
qreal fromUserValue(qreal value) const
KoUnit::Type type() const
qreal toUserValuePrecise(const qreal ptValue) const
static KoUnit fromListForUi(int index, ListOptions listOptions=ListAll, qreal factor=1.0)
static QStringList listOfUnitNameForUi(ListOptions listOptions=ListAll)
Returns the list of unit types for the UI, controlled with the given listOptions.
int indexInListForUi(ListOptions listOptions=ListAll) const
void setFactor(qreal factor)
#define KIS_SAFE_ASSERT_RECOVER(cond)
QIcon loadIcon(const QString &name)
void setText(QSpinBox *spinBox, const QStringView textTemplate)
static KoColorSpaceRegistry * instance()
static const QString pixelsCentimeterStr()
static QString pixelsInchStr()