dmz::V8Value dmz::JsModuleUiV8QtBasic::_tree_col_width (const v8::Arguments &Args) { v8::HandleScope scope; V8Value result = v8::Undefined (); JsModuleUiV8QtBasic *self = _to_self (Args); if (self) { QTreeWidget *tree = self->v8_to_qobject<QTreeWidget> (Args.This ()); if (tree) { if (Args.Length ()) { if (Args.Length () > 1) { tree->setColumnWidth (v8_to_uint32 (Args[0]), v8_to_uint32 (Args[1])); } result = v8::Number::New (tree->columnWidth (v8_to_uint32 (Args[0]))); } } } return scope.Close (result); }
void ColumnPreferencesFrame::on_columnTreeWidget_itemActivated(QTreeWidgetItem *item, int column) { if (!item || cur_line_edit_ || cur_combo_box_) return; QTreeWidget *ctw = ui->columnTreeWidget; QWidget *editor = NULL; cur_column_ = column; saved_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); switch (column) { case title_col_: { cur_line_edit_ = new QLineEdit(); cur_column_ = column; saved_col_string_ = item->text(title_col_); connect(cur_line_edit_, SIGNAL(editingFinished()), this, SLOT(columnTitleEditingFinished())); editor = cur_line_edit_; break; } case type_col_: { cur_combo_box_ = new QComboBox(); for (int i = 0; i < NUM_COL_FMTS; i++) { cur_combo_box_->addItem(col_format_desc(i), QVariant(i)); if (i == saved_combo_idx_) { cur_combo_box_->setCurrentIndex(i); } } connect(cur_combo_box_, SIGNAL(currentIndexChanged(int)), this, SLOT(columnTypeCurrentIndexChanged(int))); editor = cur_combo_box_; break; } case custom_fields_col_: { FieldFilterEdit *field_filter_edit = new FieldFilterEdit(); saved_col_string_ = item->text(custom_fields_col_); connect(field_filter_edit, SIGNAL(textChanged(QString)), field_filter_edit, SLOT(checkCustomColumn(QString))); connect(field_filter_edit, SIGNAL(editingFinished()), this, SLOT(customFieldsEditingFinished())); field_filter_edit->setFixedWidth(ctw->columnWidth(custom_fields_col_)); editor = cur_line_edit_ = field_filter_edit; //Save off the current column type in case it needs to be restored if ((item->text(custom_fields_col_) == "") && (item->text(custom_occurrence_col_) == "")) { saved_custom_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); } item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } case custom_occurrence_col_: { SyntaxLineEdit *syntax_edit = new SyntaxLineEdit(); saved_col_string_ = item->text(custom_occurrence_col_); connect(syntax_edit, SIGNAL(textChanged(QString)), syntax_edit, SLOT(checkInteger(QString))); connect(syntax_edit, SIGNAL(editingFinished()), this, SLOT(customOccurrenceEditingFinished())); syntax_edit->setFixedWidth(ctw->columnWidth(custom_occurrence_col_)); editor = cur_line_edit_ = syntax_edit; //Save off the current column type in case it needs to be restored if ((item->text(custom_fields_col_) == "") && (item->text(custom_occurrence_col_) == "")) { saved_custom_combo_idx_ = item->data(type_col_, Qt::UserRole).toInt(); } item->setText(type_col_, col_format_desc(COL_CUSTOM)); item->setData(type_col_, Qt::UserRole, QVariant(COL_CUSTOM)); break; } default: return; } if (cur_line_edit_) { cur_line_edit_->setText(saved_col_string_); cur_line_edit_->selectAll(); connect(cur_line_edit_, SIGNAL(destroyed()), this, SLOT(lineEditDestroyed())); } if (cur_combo_box_) { connect(cur_combo_box_, SIGNAL(destroyed()), this, SLOT(comboDestroyed())); } if (editor) { QFrame *edit_frame = new QFrame(); QHBoxLayout *hb = new QHBoxLayout(); QSpacerItem *spacer = new QSpacerItem(5, 10); hb->addWidget(editor, 0); hb->addSpacerItem(spacer); hb->setStretch(1, 1); hb->setContentsMargins(0, 0, 0, 0); edit_frame->setLineWidth(0); edit_frame->setFrameStyle(QFrame::NoFrame); // The documentation suggests setting autoFillbackground. That looks silly // so we clear the item text instead. item->setText(cur_column_, ""); edit_frame->setLayout(hb); ui->columnTreeWidget->setItemWidget(item, cur_column_, edit_frame); editor->setFocus(); } }