Changeset View
Standalone View
ui/annotationwidgets.cpp
Show All 13 Lines | |||||
14 | #include <qgroupbox.h> | 14 | #include <qgroupbox.h> | ||
15 | #include <qlabel.h> | 15 | #include <qlabel.h> | ||
16 | #include <qlayout.h> | 16 | #include <qlayout.h> | ||
17 | #include <qspinbox.h> | 17 | #include <qspinbox.h> | ||
18 | #include <qvariant.h> | 18 | #include <qvariant.h> | ||
19 | #include <kcolorbutton.h> | 19 | #include <kcolorbutton.h> | ||
20 | #include <kcombobox.h> | 20 | #include <kcombobox.h> | ||
21 | #include <kfontrequester.h> | 21 | #include <kfontrequester.h> | ||
22 | #include <KMessageBox> | ||||
22 | #include <QIcon> | 23 | #include <QIcon> | ||
24 | #include <QFileDialog> | ||||
23 | #include <kiconloader.h> | 25 | #include <kiconloader.h> | ||
24 | #include <KLocalizedString> | 26 | #include <KLocalizedString> | ||
25 | #include <QDebug> | 27 | #include <QDebug> | ||
26 | #include <QGuiApplication> | 28 | #include <QGuiApplication> | ||
27 | #include <QList> | 29 | #include <QList> | ||
28 | #include <QMimeDatabase> | 30 | #include <QMimeDatabase> | ||
29 | #include <QPair> | 31 | #include <QPair> | ||
30 | #include <QSize> | 32 | #include <QSize> | ||
31 | #include <KFormat> | 33 | #include <KFormat> | ||
32 | #include <QFormLayout> | 34 | #include <QFormLayout> | ||
33 | 35 | | |||
34 | #include "core/document.h" | 36 | #include "core/document.h" | ||
35 | #include "guiutils.h" | 37 | #include "guiutils.h" | ||
36 | #include "pagepainter.h" | 38 | #include "pagepainter.h" | ||
37 | 39 | | |||
38 | #define FILEATTACH_ICONSIZE 48 | 40 | #define FILEATTACH_ICONSIZE 48 | ||
39 | 41 | | |||
40 | PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent ) | 42 | PixmapPreviewSelector::PixmapPreviewSelector( QWidget * parent, PreviewPosition position ) | ||
41 | : QWidget( parent ) | 43 | : QWidget( parent ) | ||
42 | { | 44 | { | ||
43 | QHBoxLayout * mainlay = new QHBoxLayout( this ); | 45 | m_previewPosition = position; | ||
aacid: move this up to the initializer list, i.e.
, m_previewPosition( position )
after QWidget… | |||||
46 | QVBoxLayout * mainlay = new QVBoxLayout( this ); | ||||
44 | mainlay->setMargin( 0 ); | 47 | mainlay->setMargin( 0 ); | ||
48 | QHBoxLayout * toplay = new QHBoxLayout( this ); | ||||
49 | toplay->setMargin( 0 ); | ||||
50 | mainlay->addLayout( toplay ); | ||||
45 | m_comboItems = new KComboBox( this ); | 51 | m_comboItems = new KComboBox( this ); | ||
46 | mainlay->addWidget( m_comboItems ); | 52 | toplay->addWidget( m_comboItems ); | ||
47 | mainlay->setAlignment( m_comboItems, Qt::AlignTop ); | 53 | m_stampPushButton = new QPushButton(QIcon::fromTheme( "document-open" ), "", this ); | ||
aacid: "" -> QString() | |||||
pino: maybe add a tooltip to this button, just to hint users what's for | |||||
54 | m_stampPushButton->setVisible( false ); | ||||
55 | toplay->addWidget(m_stampPushButton); | ||||
48 | m_iconLabel = new QLabel( this ); | 56 | m_iconLabel = new QLabel( this ); | ||
57 | switch ( m_previewPosition ) | ||||
58 | { | ||||
59 | case Side: | ||||
60 | toplay->addWidget( m_iconLabel ); | ||||
61 | break; | ||||
62 | case Below: | ||||
49 | mainlay->addWidget( m_iconLabel ); | 63 | mainlay->addWidget( m_iconLabel ); | ||
64 | mainlay->setAlignment( m_iconLabel, Qt::AlignHCenter ); | ||||
65 | break; | ||||
66 | } | ||||
50 | m_iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | 67 | m_iconLabel->setSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); | ||
51 | m_iconLabel->setAlignment( Qt::AlignCenter ); | 68 | m_iconLabel->setAlignment( Qt::AlignCenter ); | ||
52 | m_iconLabel->setFrameStyle( QFrame::StyledPanel ); | 69 | m_iconLabel->setFrameStyle( QFrame::StyledPanel ); | ||
53 | setPreviewSize( 32 ); | 70 | setPreviewSize( 32 ); | ||
54 | 71 | | |||
55 | setFocusPolicy( Qt::TabFocus ); | 72 | setFocusPolicy( Qt::TabFocus ); | ||
56 | setFocusProxy( m_comboItems ); | 73 | setFocusProxy( m_comboItems ); | ||
57 | 74 | | |||
58 | connect( m_comboItems, SIGNAL(currentIndexChanged(QString)), this, SLOT(iconComboChanged(QString)) ); | 75 | connect( m_comboItems, SIGNAL(currentIndexChanged(QString)), this, SLOT(iconComboChanged(QString)) ); | ||
59 | connect( m_comboItems, &QComboBox::editTextChanged, this, &PixmapPreviewSelector::iconComboChanged ); | 76 | connect( m_comboItems, &QComboBox::editTextChanged, this, &PixmapPreviewSelector::iconComboChanged ); | ||
77 | connect( m_stampPushButton, SIGNAL(clicked()), this, SLOT(selectCustomStamp()) ); | ||||
aacid: Any reason not to use the "new" connect syntax based on function pointers? | |||||
60 | } | 78 | } | ||
61 | 79 | | |||
62 | PixmapPreviewSelector::~PixmapPreviewSelector() | 80 | PixmapPreviewSelector::~PixmapPreviewSelector() | ||
63 | { | 81 | { | ||
64 | } | 82 | } | ||
65 | 83 | | |||
66 | void PixmapPreviewSelector::setIcon( const QString& icon ) | 84 | void PixmapPreviewSelector::setIcon( const QString& icon ) | ||
67 | { | 85 | { | ||
Show All 20 Lines | |||||
88 | { | 106 | { | ||
89 | m_comboItems->addItem( item, QVariant( id ) ); | 107 | m_comboItems->addItem( item, QVariant( id ) ); | ||
90 | setIcon( m_icon ); | 108 | setIcon( m_icon ); | ||
91 | } | 109 | } | ||
92 | 110 | | |||
93 | void PixmapPreviewSelector::setPreviewSize( int size ) | 111 | void PixmapPreviewSelector::setPreviewSize( int size ) | ||
94 | { | 112 | { | ||
95 | m_previewSize = size; | 113 | m_previewSize = size; | ||
114 | switch( m_previewPosition ) | ||||
115 | { | ||||
116 | case Side: | ||||
96 | m_iconLabel->setFixedSize( m_previewSize + 8, m_previewSize + 8 ); | 117 | m_iconLabel->setFixedSize( m_previewSize + 8, m_previewSize + 8 ); | ||
118 | break; | ||||
119 | case Below: | ||||
120 | m_iconLabel->setFixedSize( 3 * m_previewSize + 8, m_previewSize + 8 ); | ||||
121 | break; | ||||
122 | } | ||||
97 | iconComboChanged( m_icon ); | 123 | iconComboChanged( m_icon ); | ||
98 | } | 124 | } | ||
99 | 125 | | |||
100 | int PixmapPreviewSelector::previewSize() const | 126 | int PixmapPreviewSelector::previewSize() const | ||
101 | { | 127 | { | ||
102 | return m_previewSize; | 128 | return m_previewSize; | ||
103 | } | 129 | } | ||
104 | 130 | | |||
105 | void PixmapPreviewSelector::setEditable( bool editable ) | 131 | void PixmapPreviewSelector::setEditable( bool editable ) | ||
106 | { | 132 | { | ||
107 | m_comboItems->setEditable( editable ); | 133 | m_comboItems->setEditable( editable ); | ||
134 | m_stampPushButton->setVisible( editable ); | ||||
108 | } | 135 | } | ||
109 | 136 | | |||
110 | void PixmapPreviewSelector::iconComboChanged( const QString& icon ) | 137 | void PixmapPreviewSelector::iconComboChanged( const QString& icon ) | ||
111 | { | 138 | { | ||
112 | int id = m_comboItems->findText( icon, Qt::MatchFixedString ); | 139 | int id = m_comboItems->findText( icon, Qt::MatchFixedString ); | ||
113 | if ( id >= 0 ) | 140 | if ( id >= 0 ) | ||
114 | { | 141 | { | ||
115 | m_icon = m_comboItems->itemData( id ).toString(); | 142 | m_icon = m_comboItems->itemData( id ).toString(); | ||
116 | } | 143 | } | ||
117 | else | 144 | else | ||
118 | { | 145 | { | ||
119 | m_icon = icon; | 146 | m_icon = icon; | ||
120 | } | 147 | } | ||
121 | 148 | | |||
122 | QPixmap pixmap = GuiUtils::loadStamp( m_icon, QSize(), m_previewSize ); | 149 | QPixmap pixmap = GuiUtils::loadStamp( m_icon, m_previewSize ); | ||
123 | const QRect cr = m_iconLabel->contentsRect(); | 150 | const QRect cr = m_iconLabel->contentsRect(); | ||
124 | if ( pixmap.width() > cr.width() || pixmap.height() > cr.height() ) | 151 | if ( pixmap.width() > cr.width() || pixmap.height() > cr.height() ) | ||
125 | pixmap = pixmap.scaled( cr.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); | 152 | pixmap = pixmap.scaled( cr.size(), Qt::KeepAspectRatio, Qt::SmoothTransformation ); | ||
126 | m_iconLabel->setPixmap( pixmap ); | 153 | m_iconLabel->setPixmap( pixmap ); | ||
127 | 154 | | |||
128 | emit iconChanged( m_icon ); | 155 | emit iconChanged( m_icon ); | ||
129 | } | 156 | } | ||
130 | 157 | | |||
158 | void PixmapPreviewSelector::selectCustomStamp() | ||||
159 | { | ||||
160 | const QString customStampFile = QFileDialog::getOpenFileName(this, i18n("Select custom stamp symbol"), | ||||
161 | QString(), i18n("*.ico *.png *.xpm *.svg *.svgz | Icon Files (*.ico *.png *.xpm *.svg *.svgz)") ); | ||||
ngraham: Are you sure the list of file formats should be localized? | |||||
I have copied the code from KIconLoader. I guess that "Icon Files" can be translated. Any suggestion to improve it? https://api.kde.org/frameworks/kiconthemes/html/kicondialog_8cpp_source.html#l00605 simgunz: I have copied the code from KIconLoader. I guess that "Icon Files" can be translated. Any… | |||||
ngraham: Ehh, looks like this is actually fine. | |||||
162 | if ( !customStampFile.isEmpty() ) | ||||
163 | { | ||||
164 | QPixmap pixmap = GuiUtils::loadStamp( customStampFile, m_previewSize ); | ||||
165 | if( pixmap.isNull() ) { | ||||
166 | KMessageBox::sorry( this, i18n( "Could not load the file %1", customStampFile ), "Invalid file" ); | ||||
The dialog title must be i18n'ed; while you are there, please use the @title:window semantic context with i18nc() pino: The dialog title must be i18n'ed; while you are there, please use the `@title:window` semantic… | |||||
I have also tried to add <filename> and <warning> tags as suggested in the i18n semantics tutorial, but they seem not to be processed given that the tags appears among the text when the dialog is shown. i18nc("@info", "<warning>Could not load the file <filename>%1</filename></warning>", customStampFile ) https://techbase.kde.org/Development/Tutorials/Localization/i18n_Semantics#Phrase_tags simgunz: I have also tried to add <filename> and <warning> tags as suggested in the i18n semantics… | |||||
167 | } else { | ||||
168 | m_comboItems->setEditText(customStampFile); | ||||
169 | } | ||||
170 | } | ||||
171 | } | ||||
131 | 172 | | |||
132 | AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann ) | 173 | AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann ) | ||
133 | { | 174 | { | ||
134 | switch ( ann->subType() ) | 175 | switch ( ann->subType() ) | ||
135 | { | 176 | { | ||
136 | case Okular::Annotation::AStamp: | 177 | case Okular::Annotation::AStamp: | ||
137 | return new StampAnnotationWidget( ann ); | 178 | return new StampAnnotationWidget( ann ); | ||
138 | break; | 179 | break; | ||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Line(s) | |||||
384 | 425 | | |||
385 | void StampAnnotationWidget::createStyleWidget( QFormLayout * formlayout ) | 426 | void StampAnnotationWidget::createStyleWidget( QFormLayout * formlayout ) | ||
386 | { | 427 | { | ||
387 | QWidget * widget = qobject_cast<QWidget *>( formlayout->parent() ); | 428 | QWidget * widget = qobject_cast<QWidget *>( formlayout->parent() ); | ||
388 | 429 | | |||
389 | addOpacitySpinBox( widget, formlayout ); | 430 | addOpacitySpinBox( widget, formlayout ); | ||
390 | addVerticalSpacer( formlayout ); | 431 | addVerticalSpacer( formlayout ); | ||
391 | 432 | | |||
392 | m_pixmapSelector = new PixmapPreviewSelector( widget ); | 433 | m_pixmapSelector = new PixmapPreviewSelector( widget, PixmapPreviewSelector::Below ); | ||
If this was an enum, you wouldn't need to add an inline comment explaining what it does :) ngraham: If this was an enum, you wouldn't need to add an inline comment explaining what it does :) | |||||
393 | formlayout->addRow( i18n( "Stamp symbol:" ), m_pixmapSelector ); | 434 | formlayout->addRow( i18n( "Stamp symbol:" ), m_pixmapSelector ); | ||
394 | m_pixmapSelector->setEditable( true ); | 435 | m_pixmapSelector->setEditable( true ); | ||
395 | 436 | | |||
396 | m_pixmapSelector->addItem( i18n( "Okular" ), QStringLiteral("okular") ); | 437 | m_pixmapSelector->addItem( i18n( "Okular" ), QStringLiteral("okular") ); | ||
397 | m_pixmapSelector->addItem( i18n( "Bookmark" ), QStringLiteral("bookmarks") ); | 438 | m_pixmapSelector->addItem( i18n( "Bookmark" ), QStringLiteral("bookmarks") ); | ||
398 | m_pixmapSelector->addItem( i18n( "KDE" ), QStringLiteral("kde") ); | 439 | m_pixmapSelector->addItem( i18n( "KDE" ), QStringLiteral("kde") ); | ||
399 | m_pixmapSelector->addItem( i18n( "Information" ), QStringLiteral("help-about") ); | 440 | m_pixmapSelector->addItem( i18n( "Information" ), QStringLiteral("help-about") ); | ||
400 | m_pixmapSelector->addItem( i18n( "Approved" ), QStringLiteral("Approved") ); | 441 | m_pixmapSelector->addItem( i18n( "Approved" ), QStringLiteral("Approved") ); | ||
▲ Show 20 Lines • Show All 440 Lines • Show Last 20 Lines |
move this up to the initializer list, i.e.
, m_previewPosition( position )
after QWidget( parent )