13#include <QApplication>
15#include <QDialogButtonBox>
23#include <kstandardguiitem.h>
54 static QString str = i18n(
"Pixels/Inch");
60 static QString str = i18n(
"Pixels/Centimeter");
64KisCustomImageWidget::KisCustomImageWidget(QWidget* parent, qint32 defWidth, qint32 defHeight,
double resolution,
const QString& defColorModel,
const QString& defColorDepth,
const QString& defColorProfile,
const QString& imageName)
67 setObjectName(
"KisCustomImageWidget");
68 m_openPane = qobject_cast<KisOpenPane*>(parent);
71 txtName->setText(imageName);
73 doubleWidth->setValue(defWidth);
74 doubleWidth->setDecimals(0);
80 doubleHeight->setValue(defHeight);
81 doubleHeight->setDecimals(0);
89 doubleResolution->setValue(72.0 * resolution);
90 doubleResolution->setDecimals(2);
94 sliderOpacity->setRange(0, 100, 0);
95 sliderOpacity->setValue(100);
99 connect(doubleResolution, SIGNAL(valueChanged(
double)),
101 connect(cmbWidthUnit, SIGNAL(activated(
int)),
103 connect(doubleWidth, SIGNAL(valueChanged(
double)),
105 connect(cmbHeightUnit, SIGNAL(activated(
int)),
107 connect(doubleHeight, SIGNAL(valueChanged(
double)),
109 connect(cmbResolutionUnit, SIGNAL(currentIndexChanged(
int)),
114 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setText(i18n(
"&Create"));
115 KGuiItem::assign(newDialogConfirmationButtonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
116 connect(newDialogConfirmationButtonBox, SIGNAL(accepted()),
this, SLOT(
createImage()));
120 connect(newDialogConfirmationButtonBox, SIGNAL(rejected()),
m_openPane, SLOT(reject()));
125 connect(bnPortrait, SIGNAL(clicked()), SLOT(
setPortrait()));
126 connect(bnLandscape, SIGNAL(clicked()), SLOT(
setLandscape()));
131 connect(bnSaveAsPredefined, SIGNAL(clicked()),
this, SLOT(
saveAsPredefined()));
133 colorSpaceSelector->setCurrentColorModel(
KoID(defColorModel));
134 colorSpaceSelector->setCurrentColorDepth(
KoID(defColorDepth));
135 colorSpaceSelector->setCurrentProfile(defColorProfile);
138 connect(colorSpaceSelector, SIGNAL(selectionChanged(
bool)), newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok), SLOT(setEnabled(
bool)));
145 cmbColor->setColor(bcol);
151 radioBackgroundAsRaster->setChecked(
true);
153 radioBackgroundAsFill->setChecked(
true);
155 radioBackgroundAsProjection->setChecked(
true);
163 QPalette
p = QApplication::palette();
164 QPalette palette_highlight(
p );
165 QColor c =
p.color(QPalette::Highlight);
166 palette_highlight.setColor(QPalette::Button, c);
167 bnLandscape->setPalette(palette_highlight);
168 bnPortrait->setPalette(palette_highlight);
175 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setFocus();
176 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
200 qreal resolution = doubleResolution->value();
210 doubleResolution->setValue(resolution);
216 doubleWidth->blockSignals(
true);
220 doubleWidth->setDecimals(0);
223 doubleWidth->setDecimals(2);
228 doubleWidth->blockSignals(
false);
240 doubleHeight->blockSignals(
true);
244 doubleHeight->setDecimals(0);
247 doubleHeight->setDecimals(2);
252 doubleHeight->blockSignals(
false);
264 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
false);
271 newDialogConfirmationButtonBox->button(QDialogButtonBox::Ok)->setEnabled(
true);
277 const KoColorSpace * cs = colorSpaceSelector->currentColorSpace();
284 if (profile->
name().contains(
"linear") ||
285 profile->
name().contains(
"scRGB") ||
286 profile->
info().contains(
"linear") ||
287 profile->
info().contains(
"scRGB")) {
290 QMessageBox::warning(
this,
291 i18nc(
"@title:window",
"Krita"),
292 i18n(
"Linear gamma RGB color spaces are not supposed to be used "
293 "in 8-bit integer modes. It is suggested to use 16-bit integer "
294 "or any floating point colorspace for linear profiles.\n\n"
295 "Press \"Ok\" to create a 8-bit integer linear RGB color space "
296 "or \"Cancel\" to return to the settings dialog."),
297 QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel);
299 if (result == QMessageBox::Cancel) {
300 dbgKrita <<
"Model RGB8" <<
"NOT SUPPORTED";
310 qint32 width, height;
314 resolution = doubleResolution->value() / 72.0;
316 resolution = doubleResolution->value() / 28.34;
323 QColor qc = cmbColor->color().toQColor();
328 if( radioBackgroundAsRaster->isChecked() ){
330 }
else if( radioBackgroundAsFill->isChecked() ){
334 doc->
newImage(txtName->text(), width, height, cs, bgColor, bgStyle, intNumLayers->value(), txtDescription->toPlainText(), resolution);
347 intNumLayers->setValue(layers);
352 qint32 opacity = sliderOpacity->value();
357 return (opacity * 255) / 100;
361 sliderOpacity->setValue((
value * 100) / 255);
366 cmbPredefined->clear();
369 cmbPredefined->addItem(
"");
374 if (!definitions.empty()) {
376 Q_FOREACH (
const QString &definition, definitions) {
378 if (f.open(QIODevice::ReadOnly)) {
379 QString xml = QString::fromUtf8(f.readAll());
381 predefined->fromXML(xml);
382 if (predefined->hasProperty(
"name")
383 && predefined->hasProperty(
"width")
384 && predefined->hasProperty(
"height")
385 && predefined->hasProperty(
"resolution")
386 && predefined->hasProperty(
"x-unit")
387 && predefined->hasProperty(
"y-unit")) {
389 cmbPredefined->addItem(predefined->getString(
"name"));
395 cmbPredefined->setCurrentIndex(0);
405 txtPredefinedName->setText(predefined->getString(
"name"));
407 doubleResolution->setValue(predefined->getDouble(
"resolution"));
411 cmbWidthUnit->setCurrentIndex(predefined->getInt(
"x-unit"));
412 cmbHeightUnit->setCurrentIndex(predefined->getInt(
"y-unit"));
417 doubleWidth->setValue(predefined->getDouble(
"width"));
418 doubleHeight->setValue(predefined->getDouble(
"height"));
425 QString fileName = txtPredefinedName->text();
426 if (fileName.isEmpty()) {
430 QFile f(saveLocation +
'/' + fileName.replace(
' ',
'_').replace(
'(',
'_').replace(
')',
'_').replace(
':',
'_') +
".predefinedimage");
432 if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
433 QMessageBox::warning(
this, i18nc(
"@title:window",
"Krita"),
434 i18n(
"Could not save %1.\nReason: %2.", f.fileName(), f.errorString()));
438 predefined->setProperty(
"name", txtPredefinedName->text());
439 predefined->setProperty(
"width", doubleWidth->value());
440 predefined->setProperty(
"height", doubleHeight->value());
441 predefined->setProperty(
"resolution", doubleResolution->value());
442 predefined->setProperty(
"x-unit", cmbWidthUnit->currentIndex());
443 predefined->setProperty(
"y-unit", cmbHeightUnit->currentIndex());
445 QString xml = predefined->toXML();
447 f.write(xml.toUtf8());
454 if (pr->getString(
"name") == txtPredefinedName->text()) {
465 cmbPredefined->addItem(txtPredefinedName->text());
472 if (doubleWidth->value() < doubleHeight->value()) {
479 if (doubleWidth->value() > doubleHeight->value()) {
486 double width = doubleWidth->value();
487 double height = doubleHeight->value();
489 doubleHeight->clearFocus();
490 doubleWidth->clearFocus();
492 doubleHeight->blockSignals(
true);
493 doubleWidth->blockSignals(
true);
494 cmbWidthUnit->blockSignals(
true);
495 cmbHeightUnit->blockSignals(
true);
497 doubleWidth->setValue(height);
498 doubleHeight->setValue(width);
502 doubleHeight->blockSignals(
false);
503 doubleWidth->blockSignals(
false);
504 cmbWidthUnit->blockSignals(
false);
505 cmbHeightUnit->blockSignals(
false);
515 if(doubleWidth->value() > doubleHeight->value())
516 bnLandscape->setChecked(
true);
518 bnPortrait->setChecked(
true);
524 qint64 width, height;
526 resolution = doubleResolution->value() / 72.0;
531 qint64 layerSize = width * height;
532 const KoColorSpace *cs = colorSpaceSelector->currentColorSpace();
535 QString text = i18nc(
"arg1: width. arg2: height. arg3: colorspace name. arg4: size of a channel in bits. arg5: image size",
536 "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.",
541 KFormat().formatByteSize(layerSize));
542 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"))
BackgroundStyle defaultBackgroundStyle(bool defaultValue=false) const
void setNumDefaultLayers(int num)
void setDefaultBackgroundOpacity(quint8 value)
QColor defaultBackgroundColor(bool defaultValue=false) const
void setDefaultBackgroundStyle(BackgroundStyle value)
void setDefaultBackgroundColor(const QColor &value)
int numDefaultLayers(bool defaultValue=false) const
quint8 defaultBackgroundOpacity(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()