1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include "texdocdialog.h"
#include "ui_texdocdialog.h"
#include "help.h"
#include "latexpackages.h"
TexdocDialog::TexdocDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::TexdocDialog),
packageNameValidator(this),
openButton(0)
{
ui->setupUi(this);
foreach (QAbstractButton *bt, ui->buttonBox->buttons()) {
if (ui->buttonBox->buttonRole(bt) == QDialogButtonBox::AcceptRole) {
openButton = bt;
break;
}
}
packageNameValidator.setRegExp(QRegExp("[0-9a-zA-Z\\-\\.]*"));
ui->cbPackages->lineEdit()->setValidator(&packageNameValidator);
ui->cbPackages->setMaxVisibleItems(15);
checkTimer.setSingleShot(true);
connect(&checkTimer, SIGNAL(timeout()), SLOT(checkDockAvailable()));
connect(ui->cbPackages, SIGNAL(editTextChanged(QString)), SLOT(searchTermChanged(QString)));
connect(Help::instance(), SIGNAL(texdocAvailableReply(QString, bool, QString)), SLOT(updateDocAvailableInfo(QString, bool, QString)));
updateDocAvailableInfo("", false); // initially disable warning message
}
TexdocDialog::~TexdocDialog()
{
delete ui;
}
void TexdocDialog::searchTermChanged(const QString &text)
{
ui->lbShortDescription->setText(LatexPackages::instance()->shortDescription(text));
delayedCheckDocAvailable(text);
}
void TexdocDialog::setPackageNames(const QStringList &packages)
{
ui->cbPackages->clear();
if (!packages.isEmpty()) {
QStringList pkgs(packages);
pkgs.sort();
ui->cbPackages->addItems(pkgs);
ui->cbPackages->setCurrentIndex(0);
ui->cbPackages->lineEdit()->selectAll();
}
}
void TexdocDialog::setPreferredPackage(const QString &package)
{
int index = ui->cbPackages->findText(package);
int dummyPos = 0;
QString pkgName = package; // copy because valitdate may modify it
if (index < 0 && QValidator::Acceptable == packageNameValidator.validate(pkgName, dummyPos)) {
ui->cbPackages->addItem(package);
index = ui->cbPackages->findText(package);
}
ui->cbPackages->setCurrentIndex(index);
ui->cbPackages->lineEdit()->selectAll();
}
QString TexdocDialog::selectedPackage() const
{
return ui->cbPackages->currentText();
}
// use delayed checking because the auto completion of the combo box fires two events
// one with the actually typed text and one with the completed text
void TexdocDialog::delayedCheckDocAvailable(const QString &package)
{
lastDocRequest = package;
checkTimer.start(10);
}
void TexdocDialog::checkDockAvailable()
{
if (lastDocRequest.isEmpty())
updateDocAvailableInfo("", false);
else
Help::instance()->texdocAvailableRequest(lastDocRequest);
}
void TexdocDialog::updateDocAvailableInfo(const QString &package, bool available, QString customWarning)
{
if (package != lastDocRequest) return; // the request may have come from someone else
bool showWarning = !package.isEmpty() && !available;
QString warning = customWarning.isNull() ? tr("No Documentation Available") : customWarning;
if (openButton) openButton->setEnabled(available);
ui->lbInfo->setText(showWarning ? warning : "");
ui->lbWarnIcon->setVisible(showWarning);
}
|