Exemplo n.º 1
0
void Document::mouseMoveEvent(QMouseEvent* event)
{
    m_text->viewport()->setCursor(Qt::IBeamCursor);
    unsetCursor();
    m_hide_timer->start();

    const QPoint& point = mapFromGlobal(event->globalPos());
    if (rect().contains(point)) {
        emit headerVisible(false);
        emit footerVisible(false);
    }
    setScrollBarVisible(m_scrollbar->rect().contains(m_scrollbar->mapFromGlobal(event->globalPos())));
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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);
}