Exemple #1
0
DictionaryManager::DictionaryManager(QObject *parent) :
    QObject(parent)
{
    timerDictionaryChanged.setSingleShot(true);
    connect(&timerDictionaryChanged, SIGNAL(timeout()), this, SLOT(reloadDictionary()));
    connect(&watcher, SIGNAL(fileChanged(QString)), this, SLOT(dictionaryChanged(QString)));
}
Exemple #2
0
void DictionaryLayer::changeDictionary(const QString& dictionary)
{
    qDebug() << Q_FUNC_INFO << "Changing Dictionary to " << dictionary;
    QBook::settings().setValue("setting/dictionary", dictionary);
    QBook::settings().sync();
    emit dictionaryChanged(dictionary);
}
Exemple #3
0
void KdeSpellerLayer::loadSettings()
{
	ConfigGroup group = Config().group("speller");
	m_autodetect = group.value("autodetect", false);
	QString lang = KdeSpellerSettings::suggestLanguage(group.value("language", QString()), speller());
	if (!lang.isEmpty())
		m_dictionary = lang;
	else if (!speller()->availableDictionaries().isEmpty())
		m_dictionary = speller()->availableDictionaries().begin().value();
	speller()->setLanguage(m_dictionary);
	emit dictionaryChanged();
}
Exemple #4
0
//BEGIN VariableSpellCheckEditor
VariableSpellCheckEditor::VariableSpellCheckEditor(VariableSpellCheckItem *item, QWidget *parent)
  : VariableEditor(item, parent)
{
  QGridLayout *l = (QGridLayout*) layout();

  m_dictionaryCombo = new Sonnet::DictionaryComboBox(this);
  m_dictionaryCombo->setCurrentByDictionary(item->value());
  l->addWidget(m_dictionaryCombo, 0, 2, Qt::AlignLeft);

  connect(m_dictionaryCombo, SIGNAL(dictionaryNameChanged(QString)), this, SIGNAL(valueChanged()));
  connect(m_dictionaryCombo, SIGNAL(dictionaryNameChanged(QString)), this, SLOT(activateItem()));
  connect(m_dictionaryCombo, SIGNAL(dictionaryChanged(QString)), this, SLOT(setItemValue(QString)));
}
Exemple #5
0
Document::Document(const QString& filename, int& current_wordcount, int& current_time, const QString& theme, QWidget* parent)
	: QWidget(parent),
	m_index(0),
	m_always_center(false),
	m_rich_text(false),
	m_cached_block_count(-1),
	m_cached_current_block(-1),
	m_page_type(0),
	m_page_amount(0),
	m_accurate_wordcount(true),
	m_current_wordcount(current_wordcount),
	m_current_time(current_time)
{
	setMouseTracking(true);

	m_stats = &m_document_stats;

	m_hide_timer = new QTimer(this);
	m_hide_timer->setInterval(5000);
	m_hide_timer->setSingleShot(true);
	connect(m_hide_timer, SIGNAL(timeout()), this, SLOT(hideMouse()));

	// Set up text area
        m_text = new Editor(this);
	m_text->installEventFilter(this);
	m_text->setMouseTracking(true);
	m_text->setFrameStyle(QFrame::NoFrame);
	m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_text->viewport()->setMouseTracking(true);
	m_text->viewport()->installEventFilter(this);

	QTextDocument* document = new QTextDocument(m_text);
	document->setUndoRedoEnabled(false);

	// Read file
	bool unknown_rich_text = false;
	if (!filename.isEmpty()) {
		m_rich_text = isRichTextFile(filename.toLower());
		m_filename = QFileInfo(filename).canonicalFilePath();
		updateState();

		if (!m_rich_text) {
			QFile file(filename);
			if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
				QTextStream stream(&file);
				stream.setCodec(QTextCodec::codecForName("UTF-8"));
				stream.setAutoDetectUnicode(true);
				
				QTextCursor cursor(document);
				while (!stream.atEnd()) {
					cursor.insertText(stream.read(8192));
					QApplication::processEvents();
				}
				file.close();
			}
		} else {
            PROSEUP::Reader reader;
			reader.read(filename, document);
			if (reader.hasError()) {
				QMessageBox::warning(this, tr("Sorry"), reader.errorString());
			}
		}                
	}

	// Set text area contents
	document->setUndoRedoEnabled(true);
	document->setModified(false);
	m_text->setDocument(document);
	m_text->setTabStopWidth(50);
	document->setIndentWidth(50);

	m_dictionary = new Dictionary(this);
	m_highlighter = new Highlighter(m_text, m_dictionary);
	connect(m_dictionary, SIGNAL(changed()), this, SLOT(dictionaryChanged()));

	if (m_filename.isEmpty()) {
		findIndex();
		unknown_rich_text = true;
	} else {
		m_text->setReadOnly(!QFileInfo(m_filename).isWritable());
	}

	// Set up scroll bar
	m_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_scrollbar = m_text->verticalScrollBar();
	m_scrollbar->setPalette(QApplication::palette());
	m_scrollbar->setAutoFillBackground(true);
	m_scrollbar->setVisible(false);
	connect(m_scrollbar, SIGNAL(actionTriggered(int)), this, SLOT(scrollBarActionTriggered(int)));
	connect(m_scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(scrollBarRangeChanged(int,int)));
	scrollBarRangeChanged(m_scrollbar->minimum(), m_scrollbar->maximum());

	// Lay out window
	m_layout = new QGridLayout(this);
	m_layout->setSpacing(0);
	m_layout->setMargin(0);
	m_layout->addWidget(m_text, 0, 1);
	m_layout->addWidget(m_scrollbar, 0, 2, Qt::AlignRight);

	// Load settings
	Preferences preferences;
	if (unknown_rich_text) {
		m_rich_text = preferences.richText();
	}
	m_text->setAcceptRichText(m_rich_text);
	loadPreferences(preferences);
	loadTheme(theme);


        if(m_rich_text)
        {
            m_text->setUndoRedoEnabled(false);
            cleanUpDocument();
            m_text->setUndoRedoEnabled(true);
            m_text->document()->setModified(false);
        }




	calculateWordCount();
	connect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded()));
	connect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int)));
	connect(m_text, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
	connect(m_text, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
}
Exemple #6
0
Document::Document(const QString& filename, int& current_wordcount, int& current_time, QWidget* parent)
    : QWidget(parent),
      m_cache_filename(randomCacheFilename()),
      m_index(0),
      m_always_center(false),
      m_rich_text(false),
      m_cached_block_count(-1),
      m_cached_current_block(-1),
      m_page_type(0),
      m_page_amount(0),
      m_accurate_wordcount(true),
      m_current_wordcount(current_wordcount),
      m_current_time(current_time)
{
    setMouseTracking(true);

    m_stats = &m_document_stats;

    m_hide_timer = new QTimer(this);
    m_hide_timer->setInterval(5000);
    m_hide_timer->setSingleShot(true);
    connect(m_hide_timer, SIGNAL(timeout()), this, SLOT(hideMouse()));

    // Set up text area
    m_text = new QTextEdit(this);
    m_text->installEventFilter(this);
    m_text->setMouseTracking(true);
    m_text->setFrameStyle(QFrame::NoFrame);
    m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    m_text->setTabStopWidth(50);
    m_text->document()->setIndentWidth(50);
    m_text->horizontalScrollBar()->setAttribute(Qt::WA_NoMousePropagation);
    m_text->viewport()->setMouseTracking(true);
    m_text->viewport()->installEventFilter(this);
    connect(m_text, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
    connect(m_text, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
    connect(m_text->document(), SIGNAL(undoCommandAdded()), this, SLOT(undoCommandAdded()));
    connect(m_text->document(), SIGNAL(contentsChange(int,int,int)), this, SLOT(updateWordCount(int,int,int)));

    m_dictionary = new Dictionary(this);
    m_highlighter = new Highlighter(m_text, m_dictionary);
    m_focusmode = new FocusMode(m_text);
    connect(m_dictionary, SIGNAL(changed()), this, SLOT(dictionaryChanged()));

    // Set filename
    bool unknown_rich_text = false;
    if (!filename.isEmpty()) {
        m_rich_text = isRichTextFile(filename.toLower());
        m_filename = QFileInfo(filename).canonicalFilePath();
        updateState();
    }

    if (m_filename.isEmpty()) {
        findIndex();
        unknown_rich_text = true;
    } else {
        m_text->setReadOnly(!QFileInfo(m_filename).isWritable());
    }

    // Set up scroll bar
    m_scrollbar = m_text->verticalScrollBar();
    m_scrollbar->setAttribute(Qt::WA_NoMousePropagation);
    m_scrollbar->setPalette(QApplication::palette());
    m_scrollbar->setAutoFillBackground(true);
    m_scrollbar->setMouseTracking(true);
    m_scrollbar->installEventFilter(this);
    setScrollBarVisible(false);
    connect(m_scrollbar, SIGNAL(actionTriggered(int)), this, SLOT(scrollBarActionTriggered(int)));
    connect(m_scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(scrollBarRangeChanged(int,int)));

    // Lay out window
    m_layout = new QGridLayout(this);
    m_layout->setSpacing(0);
    m_layout->setMargin(0);
    m_layout->addWidget(m_text, 0, 1);
    m_layout->addWidget(m_scrollbar, 0, 2, Qt::AlignRight);

    // Load settings
    Preferences preferences;
    if (unknown_rich_text) {
        m_rich_text = preferences.richText();
    }
    m_text->setAcceptRichText(m_rich_text);
    loadPreferences(preferences);
}
Exemple #7
0
Document::Document(const QString& filename, DailyProgress* daily_progress, QWidget* parent)
	: QWidget(parent),
	m_cache_outdated(false),
	m_index(0),
	m_always_center(false),
	m_mouse_button_down(false),
	m_rich_text(false),
	m_spacings_loaded(false),
	m_focus_mode(0),
	m_scene_list(0),
	m_dictionary(DictionaryManager::instance().requestDictionary()),
	m_cached_block_count(-1),
	m_cached_current_block(-1),
	m_saved_wordcount(0),
	m_page_type(0),
	m_page_amount(0),
	m_wordcount_type(0),
	m_daily_progress(daily_progress)
{
	setMouseTracking(true);

	m_stats = &m_document_stats;

	m_hide_timer = new QTimer(this);
	m_hide_timer->setInterval(5000);
	m_hide_timer->setSingleShot(true);
	connect(m_hide_timer, SIGNAL(timeout()), this, SLOT(hideMouse()));

	// Set up text area
	m_text = new TextEdit(this);
	m_text->installEventFilter(this);
	m_text->setMouseTracking(true);
	m_text->setFrameStyle(QFrame::NoFrame);
	m_text->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_text->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	m_text->setTabStopWidth(48);
	m_text->document()->setIndentWidth(48);
	m_text->horizontalScrollBar()->setAttribute(Qt::WA_NoMousePropagation);
	m_text->viewport()->setMouseTracking(true);
	m_text->viewport()->installEventFilter(this);
	connect(m_text, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
	connect(m_text, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
	connect(m_text->document(), SIGNAL(modificationChanged(bool)), this, SIGNAL(modificationChanged(bool)));

	QShortcut* shortcut_down = new QShortcut(m_text);
	QShortcut* shortcut_up = new QShortcut(m_text);
#ifndef Q_OS_MAC
	shortcut_down->setKey(Qt::CTRL + Qt::Key_Down);
	shortcut_up->setKey(Qt::CTRL + Qt::Key_Up);
#else
	shortcut_down->setKey(Qt::ALT + Qt::Key_Down);
	shortcut_up->setKey(Qt::ALT + Qt::Key_Up);
#endif
	connect(shortcut_down, SIGNAL(activated()), this, SLOT(moveToBlockEnd()));
	connect(shortcut_up, SIGNAL(activated()), this, SLOT(moveToBlockStart()));

	m_scene_model = new SceneModel(m_text, this);

	m_highlighter = new Highlighter(m_text, m_dictionary);
	connect(&DictionaryManager::instance(), SIGNAL(changed()), this, SLOT(dictionaryChanged()));

	// Set filename
	if (!filename.isEmpty()) {
		m_rich_text = FormatManager::isRichText(filename);
		m_filename = QFileInfo(filename).absoluteFilePath();
		updateState();
	}

	if (m_filename.isEmpty()) {
		findIndex();
	}

	// Set up scroll bar
	m_scrollbar = m_text->verticalScrollBar();
	m_scrollbar->setAttribute(Qt::WA_NoMousePropagation);
	m_scrollbar->setPalette(QApplication::palette());
	m_scrollbar->setAutoFillBackground(true);
	m_scrollbar->setMouseTracking(true);
	m_scrollbar->installEventFilter(this);
	setScrollBarVisible(Preferences::instance().alwaysShowScrollBar());
	connect(m_scrollbar, SIGNAL(actionTriggered(int)), this, SLOT(scrollBarActionTriggered(int)));
	connect(m_scrollbar, SIGNAL(rangeChanged(int,int)), this, SLOT(scrollBarRangeChanged(int,int)));

	// Lay out window
	m_layout = new QGridLayout(this);
	m_layout->setSpacing(0);
	m_layout->setMargin(0);
	m_layout->addWidget(m_text, 1, 1);
	m_layout->addWidget(m_scrollbar, 1, 2, Qt::AlignRight);

	// Load settings
	loadPreferences();

	// Make it read-only until content is loaded
	m_text->setReadOnly(true);

	DocumentWatcher::instance()->addWatch(this);
}
Exemple #8
0
void SpellCheck::toggleDialog(bool pasteText, bool preferSelection)
{
    if (!m_spellingDialog) {
        m_spellingDialog = new Plasma::Dialog();
        KWindowSystem::setState(m_spellingDialog->effectiveWinId(), NET::SkipTaskbar|NET::SkipPager);
        m_spellingDialog->setFocusPolicy(Qt::NoFocus);
        m_spellingDialog->setWindowTitle(i18n("Spell checking"));
        m_spellingDialog->setWindowIcon(KIcon("tools-check-spelling"));
        m_spellingDialog->setResizeHandleCorners(Plasma::Dialog::All);

        m_textEdit = new KTextEdit(m_spellingDialog);
        m_textEdit->enableFindReplace(false);
        m_textEdit->setCheckSpellingEnabled(true);
        m_textEdit->createHighlighter();

        m_dictionaryComboBox = new Sonnet::DictionaryComboBox(m_spellingDialog);
        m_dictionaryComboBox->setToolTip(i18n("Language"));

        KAction *spellingAction = new KAction(KIcon("tools-check-spelling"), i18n("Spell checking"), m_spellingDialog);
        KAction *copyAction = new KAction(KIcon("edit-copy"), i18n("Copy"), m_spellingDialog);
        KAction *closeAction = new KAction(KIcon("dialog-close"), i18n("Close"), m_spellingDialog);

        QToolButton *spellingButton = new QToolButton(m_spellingDialog);
        spellingButton->setDefaultAction(spellingAction);

        QToolButton *copyButton = new QToolButton(m_spellingDialog);
        copyButton->setDefaultAction(copyAction);

        QToolButton *closeButton = new QToolButton(m_spellingDialog);
        closeButton->setDefaultAction(closeAction);

        QHBoxLayout *horizontalLayout = new QHBoxLayout;
        horizontalLayout->addWidget(m_dictionaryComboBox);
        horizontalLayout->addWidget(spellingButton);
        horizontalLayout->addWidget(copyButton);
        horizontalLayout->addWidget(closeButton);

        QVBoxLayout *verticalLayout = new QVBoxLayout(m_spellingDialog);
        verticalLayout->setSpacing(0);
        verticalLayout->setMargin(0);
        verticalLayout->addWidget(m_textEdit);
        verticalLayout->addLayout(horizontalLayout);

        configChanged();

        connect(m_spellingDialog, SIGNAL(dialogResized()), this, SLOT(dialogResized()));
        connect(spellingAction, SIGNAL(triggered()), m_textEdit, SLOT(checkSpelling()));
        connect(copyAction, SIGNAL(triggered()), this, SLOT(copyToClipboard()));
        connect(closeAction, SIGNAL(triggered()), this, SLOT(toggleDialog()));
        connect(m_textEdit, SIGNAL(languageChanged(QString)), this, SLOT(setLanguage(QString)));
        connect(m_dictionaryComboBox, SIGNAL(dictionaryChanged(QString)), this, SLOT(setLanguage(QString)));
    }

    if (m_spellingDialog->isVisible()) {
        m_spellingDialog->animatedHide(Plasma::locationToInverseDirection(location()));

        m_textEdit->clear();
    } else {
        m_spellingDialog->move(popupPosition(m_spellingDialog->sizeHint()));
        m_spellingDialog->animatedShow(Plasma::locationToDirection(location()));

        if (pasteText) {
            m_textEdit->setText((!preferSelection || QApplication::clipboard()->text(QClipboard::Selection).isEmpty()) ? QApplication::clipboard()->text(QClipboard::Clipboard) : QApplication::clipboard()->text(QClipboard::Selection));
        }

        m_textEdit->setFocus();
    }
}