3 * Copyright 2001 the LyX Team
4 * Read the file COPYING
11 #include "QURLDialog.h"
12 #include "QtLyXView.h"
13 #include "BufferView.h"
21 #include <qlineedit.h>
22 #include <qcheckbox.h>
23 #include <qpushbutton.h>
25 QURL::QURL(LyXView *v, Dialogs *d)
26 : dialog_(0), lv_(v), d_(d), inset_(0), h_(0), u_(0), ih_(0)
28 // let the dialog be shown
29 // This is a permanent connection so we won't bother
30 // storing a copy because we won't be disconnecting.
31 d->showUrl.connect(slot(this, &QURL::showUrl));
32 d->createUrl.connect(slot(this, &QURL::createUrl));
42 void QURL::showUrl(InsetCommand * const inset)
44 // FIXME: when could inset be 0 here ?
49 readonly = lv_->buffer()->isReadonly();
50 //ih_ = inset_->hide.connect(slot(this,&QURL::hide));
51 params = inset->params();
57 void QURL::createUrl(string const & arg)
59 // we could already be showing a URL, clear it out
63 readonly = lv_->buffer()->isReadonly();
64 params.setFromString(arg);
71 dialog_->urlED->setText(params.getContents().c_str());
72 dialog_->nameED->setText(params.getOptions().c_str());
74 if (params.getCmdName()=="url")
75 dialog_->hyperlinkCB->setChecked(false);
77 dialog_->hyperlinkCB->setChecked(true);
80 dialog_->nameED->setFocusPolicy(QWidget::NoFocus);
81 dialog_->urlED->setFocusPolicy(QWidget::NoFocus);
82 dialog_->okPB->setEnabled(false);
83 dialog_->cancelPB->setText(_("Close"));
84 dialog_->hyperlinkCB->setEnabled(false);
86 dialog_->nameED->setFocusPolicy(QWidget::StrongFocus);
87 dialog_->urlED->setFocusPolicy(QWidget::StrongFocus);
88 dialog_->urlED->setFocus();
89 dialog_->okPB->setEnabled(true);
90 dialog_->cancelPB->setText(_("Cancel"));
91 dialog_->hyperlinkCB->setEnabled(true);
101 params.setContents(dialog_->urlED->text().latin1());
102 params.setOptions(dialog_->nameED->text().latin1());
104 if (dialog_->hyperlinkCB->isChecked())
105 params.setCmdName("htmlurl");
107 params.setCmdName("url");
110 if (params != inset_->params()) {
111 inset_->setParams(params);
112 lv_->view()->updateInset(inset_, true);
115 lv_->getLyXFunc()->dispatch(LFUN_INSERT_URL, params.getAsString().c_str());
122 dialog_ = new QURLDialog(this, 0, _("LyX: Url"), false);
124 if (!dialog_->isVisible()) {
125 h_ = d_->hideBufferDependent.connect(slot(this, &QURL::hide));
126 //u_ = d_->updateBufferDependent.connect(slot(this, &QURL::update));
130 dialog_->setActiveWindow();