QrcEditor::QrcEditor(QWidget *parent) : QWidget(parent), m_treeview(new ResourceView(&m_history)), m_addFileAction(0) { m_ui.setupUi(this); QHBoxLayout *layout = new QHBoxLayout; layout->setSpacing(0); layout->setMargin(0); m_ui.centralWidget->setLayout(layout); m_treeview->enableContextMenu(false); layout->addWidget(m_treeview); connect(m_ui.removeButton, SIGNAL(clicked()), this, SLOT(onRemove())); // 'Add' button with menu QMenu *addMenu = new QMenu(this); m_addFileAction = addMenu->addAction(tr("Add Files"), this, SLOT(onAddFiles())); addMenu->addAction(tr("Add Prefix"), this, SLOT(onAddPrefix())); m_ui.addButton->setMenu(addMenu); connect(m_treeview, SIGNAL(addPrefixTriggered()), this, SLOT(onAddPrefix())); connect(m_treeview, SIGNAL(addFilesTriggered(QString)), this, SLOT(onAddFiles())); connect(m_treeview, SIGNAL(removeItem()), this, SLOT(onRemove())); connect(m_treeview, SIGNAL(currentIndexChanged()), this, SLOT(updateCurrent())); connect(m_treeview, SIGNAL(dirtyChanged(bool)), this, SIGNAL(dirtyChanged(bool))); m_treeview->setFocus(); connect(m_ui.aliasText, SIGNAL(textEdited(QString)), this, SLOT(onAliasChanged(QString))); connect(m_ui.prefixText, SIGNAL(textEdited(QString)), this, SLOT(onPrefixChanged(QString))); connect(m_ui.languageText, SIGNAL(textEdited(QString)), this, SLOT(onLanguageChanged(QString))); // Prevent undo command merging after a switch of focus: // (0) The initial text is "Green". // (1) The user appends " is a color." --> text is "Green is a color." // (2) The user clicks into some other line edit --> loss of focus // (3) The user gives focuse again and substitutes "Green" with "Red" // --> text now is "Red is a color." // (4) The user hits undo --> text now is "Green is a color." // Without calling advanceMergeId() it would have been "Green", instead. connect(m_ui.aliasText, SIGNAL(editingFinished()), m_treeview, SLOT(advanceMergeId())); connect(m_ui.prefixText, SIGNAL(editingFinished()), m_treeview, SLOT(advanceMergeId())); connect(m_ui.languageText, SIGNAL(editingFinished()), m_treeview, SLOT(advanceMergeId())); connect(m_treeview, SIGNAL(addFilesTriggered(const QString&)), this, SIGNAL(addFilesTriggered(const QString&))); connect(&m_history, SIGNAL(canRedoChanged(bool)), this, SLOT(updateHistoryControls())); connect(&m_history, SIGNAL(canUndoChanged(bool)), this, SLOT(updateHistoryControls())); connect(&m_history, SIGNAL(canRedoChanged(bool)), this, SLOT(updateCurrent())); connect(&m_history, SIGNAL(canUndoChanged(bool)), this, SLOT(updateCurrent())); updateHistoryControls(); updateCurrent(); }
FilesEditor::FilesEditor( QSharedPointer<Component> component, QSharedPointer<FileSet> fileSet, LibraryInterface* handler, QWidget *parent, const QString& title): QGroupBox(title, parent), handler_(handler), component_(component), fileSet_(fileSet), files_(fileSet->getFiles()), view_(handler, component, this), model_(handler, component, fileSet, this), addFilesButton_(QIcon(":/icons/common/graphics/add.png"), tr("Add Files"), this) { QVBoxLayout* layout = new QVBoxLayout(this); layout->addWidget(&view_); layout->addWidget(&addFilesButton_, 0, Qt::AlignLeft); // files can not be imported/exported to a csv file view_.setAllowImportExport(false); view_.setModel(&model_); // the order of files must be maintained view_.setSortingEnabled(false); view_.setItemsDraggable(true); // set the delegate to provide editors view_.setItemDelegate(new FilesDelegate(this)); connect(&addFilesButton_, SIGNAL(clicked(bool)), this, SLOT(onAddFiles()), Qt::UniqueConnection); connect(&view_, SIGNAL(addItem(const QModelIndex&, const QString&)), &model_, SLOT(onAddItem(const QModelIndex&, const QString&)), Qt::UniqueConnection); connect(&view_, SIGNAL(removeItem(const QModelIndex&)), &model_, SLOT(onRemoveItem(const QModelIndex&)), Qt::UniqueConnection); connect(&view_, SIGNAL(moveItem(const QModelIndex&, const QModelIndex&)), &model_, SLOT(onMoveItem(const QModelIndex&, const QModelIndex&)), Qt::UniqueConnection); connect(&model_, SIGNAL(contentChanged()), this, SIGNAL(contentChanged()), Qt::UniqueConnection); // the signals from model informing that a child is added/removed connect(&model_, SIGNAL(fileAdded(int)), this, SIGNAL(fileAdded(int)), Qt::UniqueConnection); connect(&model_, SIGNAL(fileRemoved(int)), this, SIGNAL(fileRemoved(int)), Qt::UniqueConnection); connect(&model_, SIGNAL(fileMoved(int, int)), this, SIGNAL(fileMoved(int, int)), Qt::UniqueConnection); }