mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59: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();
|
||||
|
||||
connect(m_imageTitleEdit, &QLineEdit::textChanged,
|
||||
this, &VInsertImageDialog::enableOkButton);
|
||||
this, &VInsertImageDialog::handleInputChanged);
|
||||
connect(pathEdit, &QLineEdit::textChanged,
|
||||
this, &VInsertImageDialog::enableOkButton);
|
||||
this, &VInsertImageDialog::handleInputChanged);
|
||||
connect(browseBtn, &QPushButton::clicked,
|
||||
this, &VInsertImageDialog::handleBrowseBtnClicked);
|
||||
|
||||
enableOkButton();
|
||||
handleInputChanged();
|
||||
}
|
||||
|
||||
VInsertImageDialog::~VInsertImageDialog()
|
||||
@ -74,17 +74,23 @@ void VInsertImageDialog::setupUI()
|
||||
m_imageTitleEdit->setFocus();
|
||||
}
|
||||
|
||||
void VInsertImageDialog::enableOkButton()
|
||||
void VInsertImageDialog::handleInputChanged()
|
||||
{
|
||||
QString title = m_imageTitleEdit->getEvaluatedText();
|
||||
bool titleOk = !title.isEmpty();
|
||||
if (titleOk) {
|
||||
QRegExp reg(VUtils::c_imageTitleRegExp);
|
||||
titleOk = reg.exactMatch(title);
|
||||
bool pathOk = true;
|
||||
if (pathEdit->isVisible() && !pathEdit->isReadOnly()) {
|
||||
QString path = pathEdit->text();
|
||||
if (path.isEmpty()
|
||||
|| !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);
|
||||
okBtn->setEnabled(titleOk);
|
||||
okBtn->setEnabled(pathOk && titleOk);
|
||||
}
|
||||
|
||||
QString VInsertImageDialog::getImageTitleInput() const
|
||||
@ -137,7 +143,8 @@ void VInsertImageDialog::setImage(const QImage &image)
|
||||
|
||||
imagePreviewLabel->setPixmap(pixmap);
|
||||
imagePreviewLabel->setVisible(true);
|
||||
enableOkButton();
|
||||
|
||||
handleInputChanged();
|
||||
}
|
||||
|
||||
void VInsertImageDialog::setBrowseable(bool browseable, bool visible)
|
||||
@ -148,6 +155,8 @@ void VInsertImageDialog::setBrowseable(bool browseable, bool visible)
|
||||
pathLabel->setVisible(visible);
|
||||
pathEdit->setVisible(visible);
|
||||
browseBtn->setVisible(visible);
|
||||
|
||||
handleInputChanged();
|
||||
}
|
||||
|
||||
void VInsertImageDialog::imageDownloaded(const QByteArray &data)
|
||||
|
@ -31,7 +31,7 @@ public slots:
|
||||
void imageDownloaded(const QByteArray &data);
|
||||
|
||||
private slots:
|
||||
void enableOkButton();
|
||||
void handleInputChanged();
|
||||
void handleBrowseBtnClicked();
|
||||
|
||||
private:
|
||||
|
@ -33,7 +33,7 @@ QVector<QPair<QString, QString>> VUtils::s_availableLanguages;
|
||||
|
||||
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("[^\\\\/:\\*\\?\"<>\\|]*");
|
||||
|
||||
@ -106,10 +106,10 @@ QRgb VUtils::QRgbFromString(const QString &str)
|
||||
return QRgb();
|
||||
}
|
||||
|
||||
QString VUtils::generateImageFileName(const QString &path, const QString &title,
|
||||
QString VUtils::generateImageFileName(const QString &path,
|
||||
const QString &title,
|
||||
const QString &format)
|
||||
{
|
||||
Q_ASSERT(!title.isEmpty());
|
||||
QRegExp regExp("\\W");
|
||||
QString baseName(title.toLower());
|
||||
|
||||
@ -119,7 +119,9 @@ QString VUtils::generateImageFileName(const QString &path, const QString &title,
|
||||
// Constrain the length of the name.
|
||||
baseName.truncate(10);
|
||||
|
||||
baseName.prepend('_');
|
||||
if (!baseName.isEmpty()) {
|
||||
baseName.prepend('_');
|
||||
}
|
||||
|
||||
// Add current time and random number to make the name be most likely unique
|
||||
baseName = baseName + '_' + QString::number(QDateTime::currentDateTime().toTime_t());
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
extern VConfigManager *g_config;
|
||||
|
||||
const QString VMdEditOperations::c_defaultImageTitle = "image";
|
||||
const QString VMdEditOperations::c_defaultImageTitle = "";
|
||||
|
||||
VMdEditOperations::VMdEditOperations(VEdit *p_editor, VFile *p_file)
|
||||
: VEditOperations(p_editor, p_file), m_autoIndentPos(-1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user