void Transcribe::openTextFile(const QString& path) { // Because the way the UI works, we can assume that the text is not dirty // So if the file exists, we load the contents into the editor window. if (m_text_file) { m_text_file->deleteLater(); } m_text_file = new QFile(path); if (m_text_file->exists()) { if (m_text_file->open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream in_stream(m_text_file); QVariant text(in_stream.readAll()); QQmlProperty::write(m_text_area, "text", text); m_text_file->close(); setTextDirty(false); // QML has signalled text is dirty because we changed // text, so we need reset this. } else { QString msg = tr("The text file can't be read"); errorDetected(msg); m_text_file = NULL; return; } } else { // If the text file doesn't exist, empty the editor and create the file // by saving the text to it QQmlProperty::write(m_text_area, "text", QVariant("")); if (!saveText()) return; } // Update the gui emit textFileNameChanged(); QQmlProperty::write(m_main_window, "is_editable", QVariant(true)); setTextDirty(false); }
bool Transcribe::saveText() { if (!m_text_file) { // This shouldn't happen because of the GUI. We silently ignore it return false; } QSaveFile file(m_text_file->fileName()); if (file.open(QIODevice::WriteOnly | QIODevice::Text)) { #ifdef Q_OS_ANDROID // The on-screen keyboard doesn't actully add the word to the text area // until it is committed, normally by a space or period etc. To include it // in our saved file, we need to manually commit it. qApp->inputMethod()->commit(); #endif QTextStream out_stream(&file); out_stream << QQmlProperty::read(m_text_area, "text").toString(); if (file.commit()) { setTextDirty(false); return true; } } // Notify that the file could not be saved QString general_msg = tr("There was an error saving the text file.\n"); general_msg += tr("The latest changes are not saved!"); errorDetected(general_msg); return false; }
//----------------------------------------------------------------------------- void CommandLineModulesView::CreateQtPartControl( QWidget *parent ) { m_Parent = parent; if (!m_Controls) { // We create CommandLineModulesViewControls, which derives from the Qt generated class. m_Controls = new CommandLineModulesViewControls(parent); // Create a layout to contain a display of QmitkCmdLineModuleProgressWidget. m_Layout = new QVBoxLayout(m_Controls->m_RunningWidgets); m_Layout->setContentsMargins(0,0,0,0); m_Layout->setSpacing(0); // This must be done independent of other preferences, as we need it before // we create the ctkCmdLineModuleManager to initialise the Cache. this->RetrieveAndStoreTemporaryDirectoryPreferenceValues(); this->RetrieveAndStoreValidationMode(); // Start to create the command line module infrastructure. m_ModuleBackend = new ctkCmdLineModuleBackendLocalProcess(); m_ModuleManager = new ctkCmdLineModuleManager(m_ValidationMode, m_TemporaryDirectoryName); // Set the main object, the ctkCmdLineModuleManager onto all the objects that need it. m_Controls->m_ComboBox->SetManager(m_ModuleManager); m_DirectoryWatcher = new ctkCmdLineModuleDirectoryWatcher(m_ModuleManager); connect(this->m_DirectoryWatcher, SIGNAL(errorDetected(QString)), this, SLOT(OnDirectoryWatcherErrorsDetected(QString))); m_ModuleManager->registerBackend(m_ModuleBackend); // Setup the remaining preferences. this->RetrieveAndStorePreferenceValues(); // Connect signals to slots after we have set up GUI. connect(this->m_Controls->m_RunButton, SIGNAL(pressed()), this, SLOT(OnRunButtonPressed())); connect(this->m_Controls->m_RestoreDefaults, SIGNAL(pressed()), this, SLOT(OnRestoreButtonPressed())); connect(this->m_Controls->m_ComboBox, SIGNAL(actionChanged(QAction*)), this, SLOT(OnActionChanged(QAction*))); connect(this->m_Controls->m_TabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(OnTabCloseRequested(int))); connect(this->m_Controls->m_ClearXMLCache, SIGNAL(pressed()), this, SLOT(OnClearCache())); connect(this->m_Controls->m_ReloadModules, SIGNAL(pressed()), this, SLOT(OnReloadModules())); this->UpdateRunButtonEnabledStatus(); }