mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-21 04:45:31 +08:00
Icons created from a file keep the file name of that file so it can be also used to display the file in HTML code
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <QStringBuilder>
|
#include <QStringBuilder>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QDir>
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -26,8 +27,12 @@ namespace BlackMisc
|
|||||||
{ }
|
{ }
|
||||||
|
|
||||||
CIcon::CIcon(const QString &resourceFilePath, const QString &descriptiveText) :
|
CIcon::CIcon(const QString &resourceFilePath, const QString &descriptiveText) :
|
||||||
m_index(CIcons::IconIsFile), m_descriptiveText(descriptiveText), m_pixmap(CIcons::pixmapByResourceFileName(resourceFilePath))
|
m_index(CIcons::IconIsFile), m_descriptiveText(descriptiveText)
|
||||||
{}
|
{
|
||||||
|
QString fullPath;
|
||||||
|
m_pixmap = CIcons::pixmapByResourceFileName(QDir::cleanPath(resourceFilePath), fullPath);
|
||||||
|
m_fileResourcePath = fullPath;
|
||||||
|
}
|
||||||
|
|
||||||
CIcons::IconIndex CIcon::getIndex() const
|
CIcons::IconIndex CIcon::getIndex() const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -89,7 +89,13 @@ namespace BlackMisc
|
|||||||
CIcon(const QString &resourceFilePath, const QString &descriptiveText);
|
CIcon(const QString &resourceFilePath, const QString &descriptiveText);
|
||||||
|
|
||||||
//! Get descriptive text
|
//! Get descriptive text
|
||||||
const QString &getDescriptiveText() const { return this->m_descriptiveText; }
|
const QString &getDescriptiveText() const { return m_descriptiveText; }
|
||||||
|
|
||||||
|
//! Resource path if any
|
||||||
|
const QString &getFileResourcePath() const { return m_fileResourcePath; }
|
||||||
|
|
||||||
|
//! Resource path available?
|
||||||
|
bool hasFileResourcePath() const { return !m_fileResourcePath.isEmpty(); }
|
||||||
|
|
||||||
//! Index
|
//! Index
|
||||||
CIcons::IconIndex getIndex() const;
|
CIcons::IconIndex getIndex() const;
|
||||||
@@ -113,13 +119,13 @@ namespace BlackMisc
|
|||||||
QIcon toQIcon() const;
|
QIcon toQIcon() const;
|
||||||
|
|
||||||
//! Rotate by n degrees
|
//! Rotate by n degrees
|
||||||
void setRotation(int degrees) { this->m_rotateDegrees = degrees; }
|
void setRotation(int degrees) { m_rotateDegrees = degrees; }
|
||||||
|
|
||||||
//! Rotate by given degrees
|
//! Rotate by given degrees
|
||||||
void setRotation(const BlackMisc::PhysicalQuantities::CAngle &rotate);
|
void setRotation(const BlackMisc::PhysicalQuantities::CAngle &rotate);
|
||||||
|
|
||||||
//! Set descriptive text
|
//! Set descriptive text
|
||||||
void setDescriptiveText(const QString &text) { this->m_descriptiveText = text; }
|
void setDescriptiveText(const QString &text) { m_descriptiveText = text; }
|
||||||
|
|
||||||
//! Implicit conversion
|
//! Implicit conversion
|
||||||
operator QPixmap() const { return this->toPixmap(); }
|
operator QPixmap() const { return this->toPixmap(); }
|
||||||
@@ -137,13 +143,15 @@ namespace BlackMisc
|
|||||||
CIcons::IconIndex m_index = CIcons::NotSet;
|
CIcons::IconIndex m_index = CIcons::NotSet;
|
||||||
int m_rotateDegrees = 0; //!< Rotation
|
int m_rotateDegrees = 0; //!< Rotation
|
||||||
QString m_descriptiveText; //!< what does it represent?
|
QString m_descriptiveText; //!< what does it represent?
|
||||||
|
QString m_fileResourcePath; //!< file resource path
|
||||||
QPixmap m_pixmap; //!< Used with generated pixmaps, when not used with index
|
QPixmap m_pixmap; //!< Used with generated pixmaps, when not used with index
|
||||||
|
|
||||||
BLACK_METACLASS(
|
BLACK_METACLASS(
|
||||||
CIcon,
|
CIcon,
|
||||||
BLACK_METAMEMBER(index),
|
BLACK_METAMEMBER(index),
|
||||||
BLACK_METAMEMBER(rotateDegrees, 0, DisabledForComparison | DisabledForHashing),
|
BLACK_METAMEMBER(rotateDegrees, 0, DisabledForComparison | DisabledForHashing),
|
||||||
BLACK_METAMEMBER(descriptiveText)
|
BLACK_METAMEMBER(descriptiveText),
|
||||||
|
BLACK_METAMEMBER(fileResourcePath)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1222,20 +1222,20 @@ namespace BlackMisc
|
|||||||
return rotate(rotateDegrees, pixmapByIndex(index));
|
return rotate(rotateDegrees, pixmapByIndex(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
const QPixmap &CIcons::pixmapByResourceFileName(const QString &fileName)
|
const QPixmap &CIcons::pixmapByResourceFileName(const QString &relativeFileName, QString &fullFilePath)
|
||||||
{
|
{
|
||||||
//! \fixme KB 20170701 noticed the "cache" is not threadsafe. However, there has never be an issue so far. Added thread assert.
|
//! \fixme KB 20170701 noticed the "cache" is not threadsafe. However, there has never be an issue so far. Added thread assert.
|
||||||
Q_ASSERT_X(!fileName.isEmpty(), Q_FUNC_INFO, "missing filename");
|
Q_ASSERT_X(!relativeFileName.isEmpty(), Q_FUNC_INFO, "missing filename");
|
||||||
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "not thread safe");
|
Q_ASSERT_X(CThreadUtils::isCurrentThreadApplicationThread(), Q_FUNC_INFO, "not thread safe");
|
||||||
|
|
||||||
if (!getResourceFileCache().contains(fileName))
|
fullFilePath = CFileUtils::appendFilePaths(CDirectoryUtils::imagesDirectory(), relativeFileName);
|
||||||
|
if (!getResourceFileCache().contains(relativeFileName))
|
||||||
{
|
{
|
||||||
const QString path = CFileUtils::appendFilePaths(CDirectoryUtils::imagesDirectory(), fileName);
|
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
const bool s = pm.load(path);
|
const bool s = pm.load(fullFilePath);
|
||||||
getResourceFileCache().insert(fileName, s ? pm : CIcons::empty());
|
CIcons::getResourceFileCache().insert(relativeFileName, s ? pm : CIcons::empty());
|
||||||
}
|
}
|
||||||
return getResourceFileCache()[fileName];
|
return CIcons::getResourceFileCache()[relativeFileName];
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage CIcons::changeImageBackgroundColor(const QImage &imgSource, Qt::GlobalColor backgroundColor)
|
QImage CIcons::changeImageBackgroundColor(const QImage &imgSource, Qt::GlobalColor backgroundColor)
|
||||||
|
|||||||
@@ -718,7 +718,7 @@ namespace BlackMisc
|
|||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
|
|
||||||
//! Pixmap by given index
|
//! Pixmap by given index
|
||||||
static const QPixmap &pixmapByResourceFileName(const QString &fileName);
|
static const QPixmap &pixmapByResourceFileName(const QString &relativeFileName, QString &fullFilePath);
|
||||||
|
|
||||||
// -------------------------------------------------------------
|
// -------------------------------------------------------------
|
||||||
// Utility functions
|
// Utility functions
|
||||||
|
|||||||
Reference in New Issue
Block a user