Krita Source Code Documentation
Loading...
Searching...
No Matches
KoDocumentInfoDlg Class Reference

The dialog that shows information about the document. More...

#include <KoDocumentInfoDlg.h>

+ Inheritance diagram for KoDocumentInfoDlg:

Classes

class  KoDocumentInfoDlgPrivate
 

Public Slots

void accept () override
 

Signals

void saveRequested ()
 

Public Member Functions

void addPageItem (KoPageWidgetItem *item)
 
bool isDocumentSaved ()
 
 KoDocumentInfoDlg (QWidget *parent, KoDocumentInfo *docInfo)
 
QList< KPageWidgetItem * > pages () const
 
void setReadOnly (bool ro)
 
 ~KoDocumentInfoDlg () override
 

Protected Member Functions

void hideEvent (QHideEvent *event) override
 

Private Slots

void slotResetMetaData ()
 

Private Member Functions

void initAboutTab ()
 
void initAuthorTab ()
 
void saveAboutData ()
 
void updateEditingTime ()
 

Private Attributes

KoDocumentInfoDlgPrivate *const d
 

Detailed Description

The dialog that shows information about the document.

Author
Simon Hausmann hausm.nosp@m.ann@.nosp@m.kde.o.nosp@m.rg
Martin Pfeiffer hubip.nosp@m.ete@.nosp@m.gmx.n.nosp@m.et
See also
KoDocumentInfo

This dialog is invoked by KoMainWindow and shows the content of the given KoDocumentInfo class. It consists of several pages, one showing general information about the document and another showing information about the author. This dialog implements only things that are stored in the OASIS meta.xml file and therefore available through the KoDocumentInfo class. The widgets shown in the tabs are koDocumentInfoAboutWidget and koDocumentInfoAuthorWidget. This class here is derived from KPageDialog and uses the face type Tabbed.

Definition at line 39 of file KoDocumentInfoDlg.h.

Constructor & Destructor Documentation

◆ KoDocumentInfoDlg()

KoDocumentInfoDlg::KoDocumentInfoDlg ( QWidget * parent,
KoDocumentInfo * docInfo )

The constructor

Parameters
parenta pointer to the parent widget
docInfoa pointer to the shown KoDocumentInfo

Definition at line 67 of file KoDocumentInfoDlg.cpp.

68 : KPageDialog(parent)
69 , d(new KoDocumentInfoDlgPrivate)
70{
71 d->info = docInfo;
72
73 setWindowTitle(i18n("Document Information"));
74 // setInitialSize(QSize(500, 500));
75 setFaceType(KPageDialog::List);
76 setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
77 button(QDialogButtonBox::Ok)->setDefault(true);
78 KGuiItem::assign(button(QDialogButtonBox::Ok), KStandardGuiItem::ok());
79 KGuiItem::assign(button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel());
80
81 d->aboutUi = new Ui::KoDocumentInfoAboutWidget();
82 QWidget *infodlg = new QWidget();
83 d->aboutUi->setupUi(infodlg);
84 QStringList licenseExamples;
85 licenseExamples << "CC-BY 4.0" << "CC-BY-SA 4.0" << "CC-BY-SA-NC 4.0" << "CC-0";
86 QCompleter *examples = new QCompleter(licenseExamples);
87 examples->setCaseSensitivity(Qt::CaseInsensitive);
88 examples->setCompletionMode(QCompleter::PopupCompletion);
89 d->aboutUi->leLicense->setCompleter(examples);
90
91 KPageWidgetItem *page = new KPageWidgetItem(infodlg, i18n("General"));
92 page->setHeader(i18n("General"));
93
94 // Ugly hack, the mimetype should be a parameter, instead
95 KisDocument* doc = dynamic_cast< KisDocument* >(d->info->parent());
96 if (doc) {
98 } else {
99 // hide all entries not used in pages for KoDocumentInfoPropsPage
100 d->aboutUi->filePathInfoLabel->setVisible(false);
101 d->aboutUi->filePathLabel->setVisible(false);
102 d->aboutUi->filePathSeparatorLine->setVisible(false);
103 d->aboutUi->lblTypeDesc->setVisible(false);
104 d->aboutUi->lblType->setVisible(false);
105 }
106 addPage(page);
107 d->pages.append(page);
108
109 initAboutTab();
110
111 d->authorUi = new Ui::KoDocumentInfoAuthorWidget();
112 QWidget *authordlg = new QWidget();
113 d->authorUi->setupUi(authordlg);
114 page = new KPageWidgetItem(authordlg, i18n("Author"));
115 page->setHeader(i18n("Last saved by"));
116 page->setIcon(koIcon("user-identity"));
117 addPage(page);
118 d->pages.append(page);
119
121}
QByteArray mimeType
static QString iconNameForMimeType(const QString &mimeType)
The default icon name for the given mimetype.
Ui::KoDocumentInfoAuthorWidget * authorUi
KoDocumentInfoDlgPrivate *const d
#define koIcon(name)
Use these macros for icons without any issues.
Definition kis_icon.h:25
QString button(const QWheelEvent &ev)
QIcon loadIcon(const QString &name)

References KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::authorUi, button(), d, KisMimeDatabase::iconNameForMimeType(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info, initAboutTab(), initAuthorTab(), koIcon, KisIconUtils::loadIcon(), KisDocument::mimeType, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::pages.

◆ ~KoDocumentInfoDlg()

KoDocumentInfoDlg::~KoDocumentInfoDlg ( )
override

The destructor

Definition at line 123 of file KoDocumentInfoDlg.cpp.

124{
125 delete d->authorUi;
126 delete d->aboutUi;
127 delete d;
128}

References KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::authorUi, and d.

Member Function Documentation

◆ accept

void KoDocumentInfoDlg::accept ( )
overrideslot

Definition at line 130 of file KoDocumentInfoDlg.cpp.

131{
132 // check if any pages veto the close
133 Q_FOREACH (KPageWidgetItem* item, d->pages) {
134 KoPageWidgetItemAdapter *page = dynamic_cast<KoPageWidgetItemAdapter*>(item);
135 if (page) {
136 if (page->shouldDialogCloseBeVetoed()) {
137 return;
138 }
139 }
140 }
141
142 // all fine, go and apply
144 Q_FOREACH (KPageWidgetItem* item, d->pages) {
145 KoPageWidgetItemAdapter *page = dynamic_cast<KoPageWidgetItemAdapter*>(item);
146 if (page) {
147 page->apply();
148 }
149 }
150
151 KPageDialog::accept();
152}

References KoPageWidgetItemAdapter::apply(), d, KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::pages, saveAboutData(), and KoPageWidgetItemAdapter::shouldDialogCloseBeVetoed().

◆ addPageItem()

void KoDocumentInfoDlg::addPageItem ( KoPageWidgetItem * item)

Definition at line 274 of file KoDocumentInfoDlg.cpp.

275{
276 KPageWidgetItem * page = new KoPageWidgetItemAdapter(item);
277
278 addPage(page);
279 d->pages.append(page);
280}

References d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::pages.

◆ hideEvent()

void KoDocumentInfoDlg::hideEvent ( QHideEvent * event)
overrideprotected

Definition at line 229 of file KoDocumentInfoDlg.cpp.

230{
231 Q_UNUSED(event);
232}

◆ initAboutTab()

void KoDocumentInfoDlg::initAboutTab ( )
private

Sets up the aboutWidget and fills the widgets with content

Definition at line 159 of file KoDocumentInfoDlg.cpp.

160{
161 KisDocument* doc = dynamic_cast< KisDocument* >(d->info->parent());
162
163 if (doc) {
164 d->aboutUi->filePathLabel->setText(doc->localFilePath());
165 }
166
167 d->aboutUi->leTitle->setText(d->info->aboutInfo("title"));
168 d->aboutUi->leSubject->setText(d->info->aboutInfo("subject"));
169
170 d->aboutUi->leKeywords->setToolTip(i18n("Use ';' (Example: Office;KDE;Calligra)"));
171 if (!d->info->aboutInfo("keyword").isEmpty())
172 d->aboutUi->leKeywords->setText(d->info->aboutInfo("keyword"));
173
174 if (!d->info->aboutInfo("license").isEmpty()) {
175 d->aboutUi->leLicense->setText(d->info->aboutInfo("license"));
176 }
177 d->aboutUi->meDescription->setPlainText(d->info->aboutInfo("abstract"));
178 if (doc && !doc->mimeType().isEmpty()) {
179 d->aboutUi->lblType->setText(KisMimeDatabase::descriptionForMimeType(doc->mimeType()));
180 }
181 if (!d->info->aboutInfo("creation-date").isEmpty()) {
182 QDateTime t = QDateTime::fromString(d->info->aboutInfo("creation-date"),
183 Qt::ISODate);
184 QString s = QLocale().toString(t);
185 d->aboutUi->lblCreated->setText(s + ", " +
186 d->info->aboutInfo("initial-creator"));
187 }
188
189 if (!d->info->aboutInfo("date").isEmpty()) {
190 QDateTime t = QDateTime::fromString(d->info->aboutInfo("date"), Qt::ISODate);
191 QString s = QLocale().toString(t);
192 d->aboutUi->lblModified->setText(s + ", " + d->info->authorInfo("creator"));
193 }
194
195 d->aboutUi->lblRevision->setText(d->info->aboutInfo("editing-cycles"));
196
198
199 connect(d->aboutUi->pbReset, SIGNAL(clicked()),
200 this, SLOT(slotResetMetaData()));
201}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
QString localFilePath() const
static QString descriptionForMimeType(const QString &mimeType)
Find the user-readable description for the given mimetype.
QString authorInfo(const QString &info) const
QString aboutInfo(const QString &info) const

References KoDocumentInfo::aboutInfo(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, KoDocumentInfo::authorInfo(), connect(), d, KisMimeDatabase::descriptionForMimeType(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info, KisDocument::localFilePath(), KisDocument::mimeType, slotResetMetaData(), and updateEditingTime().

◆ initAuthorTab()

void KoDocumentInfoDlg::initAuthorTab ( )
private

Sets up the authorWidget and fills the widgets with content

Definition at line 203 of file KoDocumentInfoDlg.cpp.

204{
205 d->authorUi->nickName->setText(d->info->authorInfo("creator"));
206 d->authorUi->firstName->setText(d->info->authorInfo("creator-first-name"));
207 d->authorUi->lastName->setText(d->info->authorInfo("creator-last-name"));
208 d->authorUi->initials->setText(d->info->authorInfo("initial"));
209 d->authorUi->title->setText(d->info->authorInfo("author-title"));
210 d->authorUi->company->setText(d->info->authorInfo("company"));
211 d->authorUi->position->setText(d->info->authorInfo("position"));
212 QListWidget *contact = d->authorUi->leContact;
213 Q_FOREACH(QString contactMode, d->info->authorContactInfo()) {
214 if (!contactMode.isEmpty()) {
215 contact->addItem(contactMode);
216 }
217 }
218}
QStringList authorContactInfo() const
authorContactInfo

References KoDocumentInfo::authorContactInfo(), KoDocumentInfo::authorInfo(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::authorUi, d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info.

◆ isDocumentSaved()

bool KoDocumentInfoDlg::isDocumentSaved ( )

Returns true if the document was saved when the dialog was closed

Definition at line 154 of file KoDocumentInfoDlg.cpp.

References d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::documentSaved.

◆ pages()

QList< KPageWidgetItem * > KoDocumentInfoDlg::pages ( ) const

Definition at line 255 of file KoDocumentInfoDlg.cpp.

256{
257 return d->pages;
258}

References d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::pages.

◆ saveAboutData()

void KoDocumentInfoDlg::saveAboutData ( )
private

Saves the changed data back to the KoDocumentInfo class

Definition at line 220 of file KoDocumentInfoDlg.cpp.

221{
222 d->info->setAboutInfo("keyword", d->aboutUi->leKeywords->text());
223 d->info->setAboutInfo("title", d->aboutUi->leTitle->text());
224 d->info->setAboutInfo("subject", d->aboutUi->leSubject->text());
225 d->info->setAboutInfo("abstract", d->aboutUi->meDescription->toPlainText());
226 d->info->setAboutInfo("license", d->aboutUi->leLicense->text());
227}
void setAboutInfo(const QString &info, const QString &data)

References KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, d, KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info, and KoDocumentInfo::setAboutInfo().

◆ saveRequested

void KoDocumentInfoDlg::saveRequested ( )
signal

◆ setReadOnly()

void KoDocumentInfoDlg::setReadOnly ( bool ro)

Sets all fields to read-only mode. Used by the property dialog.

Definition at line 260 of file KoDocumentInfoDlg.cpp.

261{
262 d->aboutUi->meDescription->setReadOnly(ro);
263
264 Q_FOREACH(KPageWidgetItem* page, d->pages) {
265 Q_FOREACH(QLineEdit* le, page->widget()->findChildren<QLineEdit *>()) {
266 le->setReadOnly(ro);
267 }
268 Q_FOREACH(QPushButton* le, page->widget()->findChildren<QPushButton *>()) {
269 le->setDisabled(ro);
270 }
271 }
272}

References KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::pages.

◆ slotResetMetaData

void KoDocumentInfoDlg::slotResetMetaData ( )
privateslot

Connected with clicked() from pbReset - Reset parts of the metadata

Definition at line 234 of file KoDocumentInfoDlg.cpp.

235{
236 d->info->resetMetaData();
237
238 if (!d->info->aboutInfo("creation-date").isEmpty()) {
239 QDateTime t = QDateTime::fromString(d->info->aboutInfo("creation-date"),
240 Qt::ISODate);
241 QString s = QLocale().toString(t);
242 d->aboutUi->lblCreated->setText(s + ", " +
243 d->info->aboutInfo("initial-creator"));
244 }
245
246 if (!d->info->aboutInfo("date").isEmpty()) {
247 QDateTime t = QDateTime::fromString(d->info->aboutInfo("date"), Qt::ISODate);
248 QString s = QLocale().toString(t);
249 d->aboutUi->lblModified->setText(s + ", " + d->info->authorInfo("creator"));
250 }
251
252 d->aboutUi->lblRevision->setText(d->info->aboutInfo("editing-cycles"));
253}

References KoDocumentInfo::aboutInfo(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, KoDocumentInfo::authorInfo(), d, KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info, and KoDocumentInfo::resetMetaData().

◆ updateEditingTime()

void KoDocumentInfoDlg::updateEditingTime ( )
private

Definition at line 282 of file KoDocumentInfoDlg.cpp.

283{
284 const int timeElapsed = d->info->aboutInfo("editing-time").toInt();
285
286 const int secondsElapsed = timeElapsed % 60;
287 const int minutesElapsed = (timeElapsed / 60) % 60;
288 const int hoursElapsed = (timeElapsed / 3600) % 24;
289 const int daysElapsed = (timeElapsed / 86400) % 7;
290 const int weeksElapsed = timeElapsed / 604800;
291
292 QString majorTimeUnit;
293 QString minorTimeUnit;
294
295 if (weeksElapsed > 0) {
296 majorTimeUnit = i18np("%1 week", "%1 weeks", weeksElapsed);
297 minorTimeUnit = i18np("%1 day", "%1 days", daysElapsed);
298 } else if (daysElapsed > 0) {
299 majorTimeUnit = i18np("%1 day", "%1 days", daysElapsed);
300 minorTimeUnit = i18np("%1 hour", "%1 hours", hoursElapsed);
301 } else if (hoursElapsed > 0) {
302 majorTimeUnit = i18np("%1 hour", "%1 hours", hoursElapsed);
303 minorTimeUnit = i18np("%1 minute", "%1 minutes", minutesElapsed);
304 } else if (minutesElapsed > 0) {
305 majorTimeUnit = i18np("%1 minute", "%1 minutes", minutesElapsed);
306 minorTimeUnit = i18np("%1 second", "%1 seconds", secondsElapsed);
307 } else {
308 d->aboutUi->lblEditing->setText(i18np("%1 second", "%1 seconds", secondsElapsed));
309 return;
310 }
311
312 d->aboutUi->lblEditing->setText(i18nc(
313 "major time unit and minor time unit",
314 "%1 and %2",
315 majorTimeUnit,
316 minorTimeUnit
317 ));
318}

References KoDocumentInfo::aboutInfo(), KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::aboutUi, d, and KoDocumentInfoDlg::KoDocumentInfoDlgPrivate::info.

Member Data Documentation

◆ d

KoDocumentInfoDlgPrivate* const KoDocumentInfoDlg::d
private

Definition at line 88 of file KoDocumentInfoDlg.h.


The documentation for this class was generated from the following files: