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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
|
/* TRANSLATOR BALL::VIEW::LabelDialog
Necessary for lupdate.
*/
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/FORMAT/INIFile.h>
#include <BALL/VIEW/DIALOGS/labelDialog.h>
#include <BALL/VIEW/MODELS/labelModel.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/VIEW/KERNEL/common.h>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QLabel>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QLineEdit>
#include <QtWidgets/QFontDialog>
#include <QtWidgets/QRadioButton>
namespace BALL
{
namespace VIEW
{
LabelDialog::LabelDialog(QWidget* parent, const char* name)
: QDialog(parent),
Ui_LabelDialogData(),
ModularWidget(name),
id_(0)
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "new LabelDialog " << this << std::endl;
#endif
setupUi(this);
// signals and slots connections
connect( apply_button_, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( buttonCancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
connect( edit_button, SIGNAL( clicked() ), this, SLOT( editColor() ) );
connect( add_tag_button, SIGNAL( clicked() ), this, SLOT( addTag() ) );
connect( font_button, SIGNAL( clicked() ), this, SLOT( fontSelected() ) );
connect( all_items, SIGNAL( toggled(bool) ), this, SLOT( modeChanged() ) );
connect( text_box, SIGNAL( editTextChanged(const QString&) ), this, SLOT( textChanged() ) );
setWindowTitle(tr("Add Label"));
setObjectName(name);
// register the widget with the MainControl
ModularWidget::registerWidget(this);
hide();
}
LabelDialog::~LabelDialog()
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "deleting LabelDialog " << this << std::endl;
#endif
}
void LabelDialog::fetchPreferences(INIFile& inifile)
{
ModularWidget::fetchPreferences(inifile);
// the color value
if (inifile.hasEntry("WINDOWS", "Label::customcolor"))
{
custom_color_.set(inifile.getValue("WINDOWS", "Label::customcolor"));
setColor(color_sample_, custom_color_);
}
if (inifile.hasEntry("WINDOWS", "Label::font"))
{
font_.fromString(inifile.getValue("WINDOWS", "Label::font").c_str());
}
else
{
font_ = QFont("Helvetica", 12);
}
font_label->setFont(font_);
if (inifile.hasEntry("WINDOWS", "Label::manylabels"))
{
all_items->setChecked(inifile.getValue("WINDOWS", "Label::manylabels").toBool());
every_item->setChecked(!inifile.getValue("WINDOWS", "Label::manylabels").toBool());
}
}
void LabelDialog::writePreferences(INIFile& inifile)
{
ModularWidget::writePreferences(inifile);
// the color value
inifile.insertValue("WINDOWS", "Label::customcolor", custom_color_);
// the font size
inifile.insertValue("WINDOWS", "Label::font", ascii(font_.toString()));
// many <-> one label
inifile.insertValue("WINDOWS", "Label::manylabels", String(!all_items->isChecked()));
}
void LabelDialog::onNotify(Message *message)
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "LabelDialog " << this << " onNotify " << message << std::endl;
#endif
// selection => store last selection for later processing
if (RTTI::isKindOf<ControlSelectionMessage>(message))
{
ControlSelectionMessage* selection = RTTI::castTo<ControlSelectionMessage>(*message);
// disabled apply button, if selection is empty
const bool filled = !selection->getSelection().empty();
apply_button_->setEnabled(filled);
checkMenu(*getMainControl());
}
}
void LabelDialog::initializeWidget(MainControl&)
{
String description = "Shortcut|Display|Create|Label";
id_ = insertMenuEntry(MainControl::DISPLAY_CREATE, tr("&Label"), this,
SLOT(show()), description, QKeySequence("Ctrl+L"),
tr("Add a label for selected molecular objects"),
UIOperationMode::MODE_ADVANCED);
}
void LabelDialog::show()
{
raise();
QDialog::show();
}
void LabelDialog::accept()
{
list<Composite*> selection = getMainControl()->getMolecularControlSelection();
// no selection present => return
if (selection.empty()) return;
Representation* rep = new Representation;
rep->setProperty(Representation::PROPERTY__ALWAYS_FRONT);
rep->setModelType(MODEL_LABEL);
LabelModel* model = new LabelModel;
model->setText(ascii(text_box->currentText()));
model->setColor(custom_color_);
model->setFont(font_);
if ( all_items->isChecked()) model->setMode(LabelModel::ONE_LABEL);
else if ( every_atom->isChecked()) model->setMode(LabelModel::ALL_ATOMS);
else if (every_residue->isChecked()) model->setMode(LabelModel::ALL_RESIDUES);
else if ( every_item->isChecked()) model->setMode(LabelModel::ALL_ITEMS);
rep->setModelProcessor(model);
// process all objects in the selection list
list<Composite*>::const_iterator list_it = selection.begin();
list<const Composite*> composites;
for (; list_it != selection.end(); ++list_it)
{
composites.push_back(*list_it);
}
rep->setComposites(composites);
getMainControl()->insert(*rep);
getMainControl()->update(*rep);
text_box->addItem(text_box->currentText());
setStatusbarText(tr("Label added."));
}
void LabelDialog::editColor()
{
custom_color_.set(chooseColor(color_sample_));
}
void LabelDialog::addTag()
{
QString tag;
if (tag_box->currentText() == "Name") tag = "%N";
else if (tag_box->currentText() == "Residue ID") tag = "%I";
else if (tag_box->currentText() == "Atom Type") tag = "%T";
else if (tag_box->currentText() == "Atom Charge") tag = "%C";
else if (tag_box->currentText() == "Atom Type Name")tag = "%Y";
else if (tag_box->currentText() == "Element") tag = "%E";
text_box->lineEdit()->setText(text_box->currentText() + tag);
}
void LabelDialog::fontSelected()
{
bool ok = true;
QFont font = QFontDialog::getFont(&ok, font_, 0);
if (!ok) return;
font_label->setFont(font);
font_ = font;
}
void LabelDialog::modeChanged()
{
tag_box->setEnabled(!all_items->isChecked());
add_tag_button->setEnabled(!all_items->isChecked());
}
void LabelDialog::textChanged()
{
apply_button_->setEnabled(text_box->currentText() != "");
}
void LabelDialog::checkMenu(MainControl& main_control)
{
if (id_)
id_->setEnabled(main_control.getMolecularControlSelection().size() > 0 && !main_control.isBusy());
}
} } // namespaces
|