void PostWindow::post(const QString &text) { QScrollBar *scrollBar = verticalScrollBar(); bool scroll = mActions[AutoScroll]->isChecked(); QTextCursor c(document()); c.movePosition(QTextCursor::End); c.insertText(text); if (scroll) emit(scrollToBottomRequest()); }
PostWindow::PostWindow(QWidget* parent): QPlainTextEdit(parent) { setReadOnly(true); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); setFrameShape( QFrame::NoFrame ); viewport()->setAttribute( Qt::WA_MacNoClickThrough, true ); QRect availableScreenRect = qApp->desktop()->availableGeometry(this); mSizeHint = QSize( availableScreenRect.width() * 0.4, availableScreenRect.height() * 0.3 ); createActions( Main::settings() ); setContextMenuPolicy(Qt::ActionsContextMenu); connect(this, SIGNAL(scrollToBottomRequest()), this, SLOT(scrollToBottom()), Qt::QueuedConnection); applySettings( Main::settings() ); }
PostWindow::PostWindow(QWidget* parent): QPlainTextEdit(parent) { setReadOnly(true); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); QRect availableScreenRect = qApp->desktop()->availableGeometry(this); mSizeHint = QSize( availableScreenRect.width() / 2.7, 300 ); QAction * action; QAction *copyAction = new QAction(tr("Copy"), this); connect(copyAction, SIGNAL(triggered()), this, SLOT(copy())); copyAction->setShortcut( Main::settings()->shortcut("IDE/shortcuts/copy") ); copyAction->setShortcutContext( Qt::WidgetShortcut ); addAction(copyAction); mClearAction = new QAction(tr("Clear"), this); connect(mClearAction, SIGNAL(triggered()), this, SLOT(clear())); addAction(mClearAction); action = new QAction(this); action->setSeparator(true); addAction(action); action = new QAction(tr("Enlarge Post Font"), this); action->setIconText("+"); action->setShortcut(tr("Ctrl++", "Enlarge Font")); action->setShortcutContext( Qt::WidgetShortcut ); action->setToolTip(tr("Enlarge font")); connect(action, SIGNAL(triggered()), this, SLOT(zoomIn())); addAction(action); action = new QAction(tr("Shrink Post Font"), this); action->setIconText("-"); action->setShortcut(tr("Ctrl+-", "Shrink Font")); action->setShortcutContext( Qt::WidgetShortcut ); action->setToolTip(tr("Shrink font")); connect(action, SIGNAL(triggered()), this, SLOT(zoomOut())); addAction(action); action = new QAction(this); action->setSeparator(true); addAction(action); mLineWrapAction = action = new QAction(tr("Wrap Text"), this); action->setCheckable(true); addAction(action); connect( action, SIGNAL(triggered(bool)), this, SLOT(setLineWrap(bool)) ); mAutoScrollAction = new QAction(tr("Auto Scroll"), this); mAutoScrollAction->setToolTip(tr("Scroll to bottom on new posts")); mAutoScrollAction->setCheckable(true); mAutoScrollAction->setChecked(true); addAction(mAutoScrollAction); setContextMenuPolicy(Qt::ActionsContextMenu); connect(this, SIGNAL(scrollToBottomRequest()), this, SLOT(scrollToBottom()), Qt::QueuedConnection); connect(mAutoScrollAction, SIGNAL(triggered(bool)), this, SLOT(onAutoScrollTriggered(bool))); applySettings( Main::settings() ); }