config: add [global]/image_name_prefix for inserted images

This commit is contained in:
Le Tan 2018-07-15 20:06:05 +08:00
parent 40424b7931
commit 59efed94f3
5 changed files with 23 additions and 4 deletions

View File

@ -233,6 +233,9 @@ note_list_view_order=0
; 1 - 6 ; 1 - 6
outline_expanded_level=6 outline_expanded_level=6
; [optional] Prefix of the name of inserted images
image_name_prefix=
[export] [export]
; Path of the wkhtmltopdf tool ; Path of the wkhtmltopdf tool
wkhtmltopdf=wkhtmltopdf wkhtmltopdf=wkhtmltopdf

View File

@ -151,13 +151,16 @@ QString VUtils::generateImageFileName(const QString &path,
// Constrain the length of the name. // Constrain the length of the name.
baseName.truncate(10); baseName.truncate(10);
baseName.prepend(g_config->getImageNamePrefix());
if (!baseName.isEmpty()) { if (!baseName.isEmpty()) {
baseName.prepend('_'); baseName.append('_');
} }
// Add current time and random number to make the name be most likely unique // Add current time and random number to make the name be most likely unique
baseName = baseName + '_' + QString::number(QDateTime::currentDateTime().toTime_t()); baseName += QString::number(QDateTime::currentDateTime().toTime_t())
baseName = baseName + '_' + QString::number(qrand()); + '_'
+ QString::number(qrand());
QDir dir(path); QDir dir(path);
QString imageName = baseName + "." + format.toLower(); QString imageName = baseName + "." + format.toLower();

View File

@ -303,6 +303,9 @@ void VConfigManager::initialize()
m_outlineExpandedLevel = getConfigFromSettings("global", m_outlineExpandedLevel = getConfigFromSettings("global",
"outline_expanded_level").toInt(); "outline_expanded_level").toInt();
m_imageNamePrefix = getConfigFromSettings("global",
"image_name_prefix").toString();
} }
void VConfigManager::initSettings() void VConfigManager::initSettings()

View File

@ -520,6 +520,8 @@ public:
int getOutlineExpandedLevel() const; int getOutlineExpandedLevel() const;
void setOutlineExpandedLevel(int p_level); void setOutlineExpandedLevel(int p_level);
const QString &getImageNamePrefix() const;
private: private:
// Look up a config from user and default settings. // Look up a config from user and default settings.
QVariant getConfigFromSettings(const QString &section, const QString &key) const; QVariant getConfigFromSettings(const QString &section, const QString &key) const;
@ -936,6 +938,9 @@ private:
// Expanded level of outline. // Expanded level of outline.
int m_outlineExpandedLevel; int m_outlineExpandedLevel;
// Prefix of the name of inserted images.
QString m_imageNamePrefix;
// The name of the config file in each directory. // The name of the config file in each directory.
static const QString c_dirConfigFile; static const QString c_dirConfigFile;
@ -2444,4 +2449,9 @@ inline void VConfigManager::setOutlineExpandedLevel(int p_level)
m_outlineExpandedLevel = p_level; m_outlineExpandedLevel = p_level;
setConfigToSettings("global", "outline_expanded_level", m_outlineExpandedLevel); setConfigToSettings("global", "outline_expanded_level", m_outlineExpandedLevel);
} }
inline const QString &VConfigManager::getImageNamePrefix() const
{
return m_imageNamePrefix;
}
#endif // VCONFIGMANAGER_H #endif // VCONFIGMANAGER_H

View File

@ -42,7 +42,7 @@ VWebView::VWebView(VFile *p_file, QWidget *p_parent)
void VWebView::contextMenuEvent(QContextMenuEvent *p_event) void VWebView::contextMenuEvent(QContextMenuEvent *p_event)
{ {
if (m_inPreview) { if (m_inPreview) {
QWebEngineView(p_event); QWebEngineView::contextMenuEvent(p_event);
return; return;
} }