mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
use empty title by default when inserting new image
This commit is contained in:
parent
ce2a572211
commit
34aa9e0083
@ -13,13 +13,13 @@ VInsertImageDialog::VInsertImageDialog(const QString &title, const QString &defa
|
|||||||
setupUI();
|
setupUI();
|
||||||
|
|
||||||
connect(m_imageTitleEdit, &QLineEdit::textChanged,
|
connect(m_imageTitleEdit, &QLineEdit::textChanged,
|
||||||
this, &VInsertImageDialog::enableOkButton);
|
this, &VInsertImageDialog::handleInputChanged);
|
||||||
connect(pathEdit, &QLineEdit::textChanged,
|
connect(pathEdit, &QLineEdit::textChanged,
|
||||||
this, &VInsertImageDialog::enableOkButton);
|
this, &VInsertImageDialog::handleInputChanged);
|
||||||
connect(browseBtn, &QPushButton::clicked,
|
connect(browseBtn, &QPushButton::clicked,
|
||||||
this, &VInsertImageDialog::handleBrowseBtnClicked);
|
this, &VInsertImageDialog::handleBrowseBtnClicked);
|
||||||
|
|
||||||
enableOkButton();
|
handleInputChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
VInsertImageDialog::~VInsertImageDialog()
|
VInsertImageDialog::~VInsertImageDialog()
|
||||||
@ -74,17 +74,23 @@ void VInsertImageDialog::setupUI()
|
|||||||
m_imageTitleEdit->setFocus();
|
m_imageTitleEdit->setFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VInsertImageDialog::enableOkButton()
|
void VInsertImageDialog::handleInputChanged()
|
||||||
{
|
{
|
||||||
QString title = m_imageTitleEdit->getEvaluatedText();
|
bool pathOk = true;
|
||||||
bool titleOk = !title.isEmpty();
|
if (pathEdit->isVisible() && !pathEdit->isReadOnly()) {
|
||||||
if (titleOk) {
|
QString path = pathEdit->text();
|
||||||
QRegExp reg(VUtils::c_imageTitleRegExp);
|
if (path.isEmpty()
|
||||||
titleOk = reg.exactMatch(title);
|
|| !VUtils::checkPathLegal(path)) {
|
||||||
|
pathOk = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString title = m_imageTitleEdit->getEvaluatedText();
|
||||||
|
QRegExp reg(VUtils::c_imageTitleRegExp);
|
||||||
|
bool titleOk = reg.exactMatch(title);
|
||||||
|
|
||||||
QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok);
|
QPushButton *okBtn = m_btnBox->button(QDialogButtonBox::Ok);
|
||||||
okBtn->setEnabled(titleOk);
|
okBtn->setEnabled(pathOk && titleOk);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VInsertImageDialog::getImageTitleInput() const
|
QString VInsertImageDialog::getImageTitleInput() const
|
||||||
@ -137,7 +143,8 @@ void VInsertImageDialog::setImage(const QImage &image)
|
|||||||
|
|
||||||
imagePreviewLabel->setPixmap(pixmap);
|
imagePreviewLabel->setPixmap(pixmap);
|
||||||
imagePreviewLabel->setVisible(true);
|
imagePreviewLabel->setVisible(true);
|
||||||
enableOkButton();
|
|
||||||
|
handleInputChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VInsertImageDialog::setBrowseable(bool browseable, bool visible)
|
void VInsertImageDialog::setBrowseable(bool browseable, bool visible)
|
||||||
@ -148,6 +155,8 @@ void VInsertImageDialog::setBrowseable(bool browseable, bool visible)
|
|||||||
pathLabel->setVisible(visible);
|
pathLabel->setVisible(visible);
|
||||||
pathEdit->setVisible(visible);
|
pathEdit->setVisible(visible);
|
||||||
browseBtn->setVisible(visible);
|
browseBtn->setVisible(visible);
|
||||||
|
|
||||||
|
handleInputChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VInsertImageDialog::imageDownloaded(const QByteArray &data)
|
void VInsertImageDialog::imageDownloaded(const QByteArray &data)
|
||||||
|
@ -31,7 +31,7 @@ public slots:
|
|||||||
void imageDownloaded(const QByteArray &data);
|
void imageDownloaded(const QByteArray &data);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void enableOkButton();
|
void handleInputChanged();
|
||||||
void handleBrowseBtnClicked();
|
void handleBrowseBtnClicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -33,7 +33,7 @@ QVector<QPair<QString, QString>> VUtils::s_availableLanguages;
|
|||||||
|
|
||||||
const QString VUtils::c_imageLinkRegExp = QString("\\!\\[([^\\]]*)\\]\\(([^\\)\"]+)\\s*(\"(\\\\.|[^\"\\)])*\")?\\s*\\)");
|
const QString VUtils::c_imageLinkRegExp = QString("\\!\\[([^\\]]*)\\]\\(([^\\)\"]+)\\s*(\"(\\\\.|[^\"\\)])*\")?\\s*\\)");
|
||||||
|
|
||||||
const QString VUtils::c_imageTitleRegExp = QString("[\\w\\(\\)@#%\\*\\-\\+=\\?<>\\,\\.\\s]+");
|
const QString VUtils::c_imageTitleRegExp = QString("[\\w\\(\\)@#%\\*\\-\\+=\\?<>\\,\\.\\s]*");
|
||||||
|
|
||||||
const QString VUtils::c_fileNameRegExp = QString("[^\\\\/:\\*\\?\"<>\\|]*");
|
const QString VUtils::c_fileNameRegExp = QString("[^\\\\/:\\*\\?\"<>\\|]*");
|
||||||
|
|
||||||
@ -106,10 +106,10 @@ QRgb VUtils::QRgbFromString(const QString &str)
|
|||||||
return QRgb();
|
return QRgb();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString VUtils::generateImageFileName(const QString &path, const QString &title,
|
QString VUtils::generateImageFileName(const QString &path,
|
||||||
|
const QString &title,
|
||||||
const QString &format)
|
const QString &format)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!title.isEmpty());
|
|
||||||
QRegExp regExp("\\W");
|
QRegExp regExp("\\W");
|
||||||
QString baseName(title.toLower());
|
QString baseName(title.toLower());
|
||||||
|
|
||||||
@ -119,7 +119,9 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title,
|
|||||||
// Constrain the length of the name.
|
// Constrain the length of the name.
|
||||||
baseName.truncate(10);
|
baseName.truncate(10);
|
||||||
|
|
||||||
|
if (!baseName.isEmpty()) {
|
||||||
baseName.prepend('_');
|
baseName.prepend('_');
|
||||||
|
}
|
||||||
|
|
||||||
// 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 = baseName + '_' + QString::number(QDateTime::currentDateTime().toTime_t());
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
extern VConfigManager *g_config;
|
extern VConfigManager *g_config;
|
||||||
|
|
||||||
const QString VMdEditOperations::c_defaultImageTitle = "image";
|
const QString VMdEditOperations::c_defaultImageTitle = "";
|
||||||
|
|
||||||
VMdEditOperations::VMdEditOperations(VEdit *p_editor, VFile *p_file)
|
VMdEditOperations::VMdEditOperations(VEdit *p_editor, VFile *p_file)
|
||||||
: VEditOperations(p_editor, p_file), m_autoIndentPos(-1)
|
: VEditOperations(p_editor, p_file), m_autoIndentPos(-1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user