Changeset View
Changeset View
Standalone View
Standalone View
ui/guiutils.cpp
Show First 20 Lines • Show All 163 Lines • ▼ Show 20 Line(s) | 157 | { | |||
---|---|---|---|---|---|
164 | if ( !contents.isEmpty() ) | 164 | if ( !contents.isEmpty() ) | ||
165 | tooltip += QStringLiteral( "<div style=\"font-size: 4px;\"><hr /></div>" ) + contents; | 165 | tooltip += QStringLiteral( "<div style=\"font-size: 4px;\"><hr /></div>" ) + contents; | ||
166 | 166 | | |||
167 | tooltip += QLatin1String("</qt>"); | 167 | tooltip += QLatin1String("</qt>"); | ||
168 | 168 | | |||
169 | return tooltip; | 169 | return tooltip; | ||
170 | } | 170 | } | ||
171 | 171 | | |||
172 | QPixmap loadStamp( const QString& _name, const QSize& size, int iconSize ) | 172 | QPixmap loadStamp( const QString& nameOrPath, int size, bool keepAspectRatio ) | ||
173 | { | 173 | { | ||
174 | const QString name = _name.toLower(); | 174 | const QString name = nameOrPath.toLower(); | ||
175 | | ||||
176 | // _name is the name of an Okular stamp symbols ( multiple symbols in a single *.svg file) | ||||
175 | QSvgRenderer * r = nullptr; | 177 | QSvgRenderer * r = nullptr; | ||
176 | if ( ( r = s_data->svgStamps() ) && r->elementExists( name ) ) | 178 | if ( ( r = s_data->svgStamps() ) && r->elementExists( name ) ) | ||
177 | { | 179 | { | ||
178 | const QRectF stampElemRect = r->boundsOnElement( name ); | 180 | const QSize stampSize = r->boundsOnElement( name ).size().toSize(); | ||
179 | const QRectF stampRect( size.isValid() ? QRectF( QPointF( 0, 0 ), size ) : stampElemRect ); | 181 | const QSize pixmapSize = stampSize.scaled( size, size, | ||
180 | QPixmap pixmap( stampRect.size().toSize() ); | 182 | keepAspectRatio ? Qt::KeepAspectRatioByExpanding | ||
183 | : Qt::IgnoreAspectRatio ); | ||||
184 | QPixmap pixmap( pixmapSize ); | ||||
181 | pixmap.fill( Qt::transparent ); | 185 | pixmap.fill( Qt::transparent ); | ||
182 | QPainter p( &pixmap ); | 186 | QPainter p( &pixmap ); | ||
183 | r->render( &p, name ); | 187 | r->render( &p, name ); | ||
184 | p.end(); | 188 | p.end(); | ||
185 | return pixmap; | 189 | return pixmap; | ||
186 | } | 190 | } | ||
191 | | ||||
192 | // _name is a path (do this before loading as icon name to avoid some rare weirdness ) | ||||
187 | QPixmap pixmap; | 193 | QPixmap pixmap; | ||
194 | pixmap.load( nameOrPath ); | ||||
195 | if ( !pixmap.isNull() ) { | ||||
196 | pixmap = pixmap.scaled( size, size, | ||||
197 | keepAspectRatio ? Qt::KeepAspectRatioByExpanding | ||||
198 | : Qt::IgnoreAspectRatio, | ||||
199 | Qt::SmoothTransformation ); | ||||
200 | return pixmap; | ||||
201 | } | ||||
202 | | ||||
203 | // _name is an icon name | ||||
188 | const KIconLoader * il = iconLoader(); | 204 | const KIconLoader * il = iconLoader(); | ||
189 | QString path; | 205 | QString path; | ||
190 | const int minSize = iconSize > 0 ? iconSize : qMin( size.width(), size.height() ); | 206 | pixmap = il->loadIcon( name, KIconLoader::User, size, KIconLoader::DefaultState, QStringList(), &path, true ); | ||
191 | pixmap = il->loadIcon( name, KIconLoader::User, minSize, KIconLoader::DefaultState, QStringList(), &path, true ); | | |||
192 | if ( path.isEmpty() ) | 207 | if ( path.isEmpty() ) | ||
193 | pixmap = il->loadIcon( name, KIconLoader::NoGroup, minSize ); | 208 | pixmap = il->loadIcon( name, KIconLoader::NoGroup, size ); | ||
194 | return pixmap; | 209 | | ||
210 | return pixmap; // can be a null pixmap | ||||
195 | } | 211 | } | ||
196 | 212 | | |||
197 | void addIconLoader( KIconLoader * loader ) | 213 | void addIconLoader( KIconLoader * loader ) | ||
198 | { | 214 | { | ||
199 | s_data->il.append( loader ); | 215 | s_data->il.append( loader ); | ||
200 | } | 216 | } | ||
201 | 217 | | |||
202 | void removeIconLoader( KIconLoader * loader ) | 218 | void removeIconLoader( KIconLoader * loader ) | ||
▲ Show 20 Lines • Show All 83 Lines • Show Last 20 Lines |