]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QRefDialog.C
This new citation dialog follows a new design similar to lyx-1.3:
[lyx.git] / src / frontends / qt4 / QRefDialog.C
1 /**
2  * \file QRefDialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Kalle Dalheimer
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "QRefDialog.h"
15 #include "QRef.h"
16
17 #include <qlineedit.h>
18 #include <q3listbox.h>
19 #include <qpushbutton.h>
20 //Added by qt3to4:
21 #include <QCloseEvent>
22
23 namespace lyx {
24 namespace frontend {
25
26 QRefDialog::QRefDialog(QRef * form)
27         : form_(form)
28 {
29         setupUi(this);
30
31         connect(okPB, SIGNAL(clicked()),
32                 form_, SLOT(slotOK()));
33         connect(applyPB, SIGNAL(clicked()),
34                 form_, SLOT(slotApply()));
35         connect(closePB, SIGNAL(clicked()),
36                 form_, SLOT(slotClose()));
37
38     connect( typeCO, SIGNAL( activated(int) ), this, SLOT( changed_adaptor() ) );
39     connect( referenceED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
40     connect( nameED, SIGNAL( textChanged(const QString&) ), this, SLOT( changed_adaptor() ) );
41     connect( refsLB, SIGNAL( highlighted(const QString&) ), this, SLOT( refHighlighted(const QString&) ) );
42     connect( refsLB, SIGNAL( selected(const QString&) ), this, SLOT( refSelected(const QString&) ) );
43     connect( sortCB, SIGNAL( toggled(bool) ), this, SLOT( sortToggled(bool) ) );
44     connect( gotoPB, SIGNAL( clicked() ), this, SLOT( gotoClicked() ) );
45     connect( updatePB, SIGNAL( clicked() ), this, SLOT( updateClicked() ) );
46     connect( bufferCO, SIGNAL( activated(int) ), this, SLOT( updateClicked() ) );
47
48 }
49
50 void QRefDialog::show()
51 {
52         QDialog::show();
53         refsLB->setFocus();
54 }
55
56
57 void QRefDialog::changed_adaptor()
58 {
59         form_->changed();
60 }
61
62
63 void QRefDialog::gotoClicked()
64 {
65         form_->gotoRef();
66 }
67
68
69 void QRefDialog::refHighlighted(const QString & sel)
70 {
71         if (form_->readOnly())
72                 return;
73
74         int const cur_item = refsLB->currentItem();
75         bool const cur_item_selected = cur_item >= 0 ?
76                 refsLB->isSelected(cur_item) : false;
77
78         if (cur_item_selected)
79                 referenceED->setText(sel);
80
81         if (form_->at_ref_)
82                 form_->gotoRef();
83         gotoPB->setEnabled(true);
84         if (form_->typeAllowed())
85                 typeCO->setEnabled(true);
86         if (form_->nameAllowed())
87                 nameED->setEnabled(true);
88 }
89
90
91 void QRefDialog::refSelected(const QString & sel)
92 {
93         if (form_->readOnly())
94                 return;
95
96         int const cur_item = refsLB->currentItem();
97         bool const cur_item_selected = cur_item >= 0 ?
98                 refsLB->isSelected(cur_item) : false;
99          
100         if (cur_item_selected)          
101                 referenceED->setText(sel);
102         // <enter> or double click, inserts ref and closes dialog
103         form_->slotOK();
104 }
105
106
107 void QRefDialog::sortToggled(bool on)
108 {
109         form_->sort_ = on;
110         form_->redoRefs();
111 }
112
113
114 void QRefDialog::updateClicked()
115 {
116         form_->updateRefs();
117 }
118
119
120 void QRefDialog::closeEvent(QCloseEvent * e)
121 {
122         form_->slotWMHide();
123         e->accept();
124 }
125
126 } // namespace frontend
127 } // namespace lyx