]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QRefDialog.C
Add vertical spacer.
[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>
18 #include <QListWidget>
19 #include <QPushButton>
20 #include <QCloseEvent>
21
22 namespace lyx {
23 namespace frontend {
24
25 QRefDialog::QRefDialog(QRef * form)
26         : form_(form)
27 {
28         setupUi(this);
29
30         connect(okPB, SIGNAL(clicked()),
31                 form_, SLOT(slotOK()));
32         connect(applyPB, SIGNAL(clicked()),
33                 form_, SLOT(slotApply()));
34         connect(closePB, SIGNAL(clicked()),
35                 form_, SLOT(slotClose()));
36
37         connect( typeCO, SIGNAL( activated(int) ), 
38                 this, SLOT( changed_adaptor() ) );
39         connect( referenceED, SIGNAL( textChanged(const QString&) ), 
40                 this, SLOT( changed_adaptor() ) );
41         connect( nameED, SIGNAL( textChanged(const QString&) ), 
42                 this, SLOT( changed_adaptor() ) );
43         connect( refsLW, SIGNAL(  itemClicked(QListWidgetItem *) ), 
44                 this, SLOT( refHighlighted(QListWidgetItem *) ) );
45         connect( refsLW, SIGNAL(  itemSelectionChanged() ),
46                 this, SLOT( selectionChanged() ) );
47         connect( refsLW, SIGNAL(  itemActivated(QListWidgetItem *) ), 
48                 this, SLOT( refSelected(QListWidgetItem *) ) );
49         connect( sortCB, SIGNAL( clicked(bool) ),
50                 this, SLOT( sortToggled(bool) ) );
51         connect( gotoPB, SIGNAL( clicked() ), 
52                 this, SLOT( gotoClicked() ) );
53         connect( updatePB, SIGNAL( clicked() ), 
54                 this, SLOT( updateClicked() ) );
55         connect( bufferCO, SIGNAL( activated(int) ), 
56                 this, SLOT( updateClicked() ) );
57
58         setFocusProxy(refsLW);
59 }
60
61 void QRefDialog::show()
62 {
63         QDialog::show();
64 }
65
66
67 void QRefDialog::changed_adaptor()
68 {
69         form_->changed();
70 }
71
72
73 void QRefDialog::gotoClicked()
74 {
75         form_->gotoRef();
76 }
77
78 void QRefDialog::selectionChanged()
79 {
80         if (form_->readOnly())
81                 return;
82         
83         QList<QListWidgetItem *> selections = refsLW->selectedItems();
84         if (selections.isEmpty())
85                 return;
86         QListWidgetItem * sel = selections.first();
87         refHighlighted(sel);
88         return;
89 }
90
91 void QRefDialog::refHighlighted(QListWidgetItem * sel)
92 {
93         if (form_->readOnly())
94                 return;
95
96 /*      int const cur_item = refsLW->currentRow();
97         bool const cur_item_selected = cur_item >= 0 ?
98                 refsLB->isSelected(cur_item) : false;*/
99         bool const cur_item_selected = refsLW->isItemSelected(sel);
100
101         if (cur_item_selected)
102                 referenceED->setText(sel->text());
103
104         if (form_->at_ref_)
105                 form_->gotoRef();
106         gotoPB->setEnabled(true);
107         if (form_->typeAllowed())
108                 typeCO->setEnabled(true);
109         if (form_->nameAllowed())
110                 nameED->setEnabled(true);
111 }
112
113
114 void QRefDialog::refSelected(QListWidgetItem * sel)
115 {
116         if (form_->readOnly())
117                 return;
118
119 /*      int const cur_item = refsLW->currentRow();
120         bool const cur_item_selected = cur_item >= 0 ?
121                 refsLB->isSelected(cur_item) : false;*/
122         bool const cur_item_selected = refsLW->isItemSelected(sel);
123
124         if (cur_item_selected)
125                 referenceED->setText(sel->text());
126         // <enter> or double click, inserts ref and closes dialog
127         form_->slotOK();
128 }
129
130
131 void QRefDialog::sortToggled(bool on)
132 {
133         form_->sort_ = on;
134         form_->redoRefs();
135 }
136
137
138 void QRefDialog::updateClicked()
139 {
140         form_->updateRefs();
141 }
142
143
144 void QRefDialog::closeEvent(QCloseEvent * e)
145 {
146         form_->slotWMHide();
147         e->accept();
148 }
149
150 } // namespace frontend
151 } // namespace lyx
152
153 #include "QRefDialog_moc.cpp"