#include "BufferView.h"
#include "CoordCache.h"
#include "Cursor.h"
-#include "debug.h"
#include "Font.h"
#include "FuncRequest.h"
-#include "gettext.h"
#include "GuiApplication.h"
#include "GuiKeySymbol.h"
#include "GuiPainter.h"
+#include "GuiView.h"
#include "KeySymbol.h"
#include "Language.h"
#include "LyXFunc.h"
#include "graphics/GraphicsImage.h"
#include "graphics/GraphicsLoader.h"
+#include "support/debug.h"
+#include "support/gettext.h"
#include "support/FileName.h"
-#include "support/ForkedcallsController.h"
+#include "support/ForkedCalls.h"
#include "frontends/Application.h"
-#include "frontends/Dialogs.h" // only used in setReadOnly
#include "frontends/FontMetrics.h"
-#include "frontends/LyXView.h"
#include "frontends/WorkAreaManager.h"
#include <QInputContext>
#include <QTimer>
#include <boost/bind.hpp>
-#include <boost/current_function.hpp>
#ifdef Q_WS_X11
#include <QX11Info>
namespace lyx {
using support::FileName;
-using support::ForkedcallsController;
/// return the LyX mouse button state from Qt's
-// All the below connection objects are needed because of a bug in some
-// versions of GCC (<=2.96 are on the suspects list.) By having and assigning
-// to these connections we avoid a segfault upon startup, and also at exit.
-// (Lgb)
-
-static boost::signals::connection timecon;
-
-// HACK: FIXME
-WorkArea::~WorkArea() {}
-
-
-GuiWorkArea::GuiWorkArea(Buffer & buffer, LyXView & lv)
+GuiWorkArea::GuiWorkArea(Buffer & buffer, GuiView & lv)
: buffer_view_(new BufferView(buffer)), lyx_view_(&lv),
- cursor_visible_(false), cursor_timeout_(400),
+ cursor_visible_(false),
need_resize_(false), schedule_redraw_(false),
preedit_lines_(1)
{
buffer.workAreaManager().add(this);
// Setup the signals
- timecon = cursor_timeout_.timeout
- .connect(boost::bind(&GuiWorkArea::toggleCursor, this));
+ cursor_timeout_.setInterval(400);
+ connect(&cursor_timeout_, SIGNAL(timeout()),
+ this, SLOT(toggleCursor()));
cursor_timeout_.start();
cursor_ = new frontend::CursorWidget();
cursor_->hide();
- setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
+ setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setAcceptDrops(true);
setMouseTracking(true);
// PageStep only depends on the viewport height.
verticalScrollBar()->setPageStep(viewport()->height());
- LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION
- << "\n Area width\t" << width()
- << "\n Area height\t" << height()
- << "\n viewport width\t" << viewport()->width()
- << "\n viewport height\t" << viewport()->height()
- << endl;
+ LYXERR(Debug::GUI, "viewport width: " << viewport()->width()
+ << " viewport height: " << viewport()->height());
// Enables input methods for asian languages.
// Must be set when creating custom text editing widgets.
{
buffer_view_->buffer().workAreaManager().remove(this);
delete buffer_view_;
+ delete cursor_;
}
void GuiWorkArea::startBlinkingCursor()
{
showCursor();
- cursor_timeout_.restart();
+ cursor_timeout_.start();
}
// No need to do anything if this is the current view. The BufferView
// metrics are already up to date.
- if (lyx_view_ != theApp()->currentView()) {
+ if (lyx_view_ != guiApp->currentView()) {
// FIXME: it would be nice to optimize for the off-screen case.
buffer_view_->updateMetrics();
buffer_view_->cursor().fixIfBroken();
showCursor();
}
- ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
-
- LYXERR(Debug::WORKAREA) << "WorkArea::redraw screen" << endl;
-
- int const ymin = std::max(vi.y1, 0);
- int const ymax = vi.p2 < vi.size - 1 ? vi.y2 : height();
-
- expose(0, ymin, width(), ymax - ymin);
+ LYXERR(Debug::WORKAREA, "WorkArea::redraw screen");
+ updateScreen();
+ update(0, 0, viewport()->width(), viewport()->height());
- //LYXERR(Debug::WORKAREA)
- //<< " ymin = " << ymin << " width() = " << width()
-// << " ymax-ymin = " << ymax-ymin << std::endl;
+ lyx_view_->updateStatusBar();
if (lyxerr.debugging(Debug::WORKAREA))
buffer_view_->coordCache().dump();
// Skip these when selecting
if (cmd.action != LFUN_MOUSE_MOTION) {
- lyx_view_->updateLayoutChoice(false);
+ lyx_view_->updateLayoutList();
lyx_view_->updateToolbars();
}
// WARNING: Please don't put any code that will trigger a repaint here!
// We are already inside a paint event.
lyx_view_->setBusy(true);
- buffer_view_->resize(width(), height());
- lyx_view_->updateLayoutChoice(false);
+ buffer_view_->resize(viewport()->width(), viewport()->height());
+ lyx_view_->updateLayoutList();
lyx_view_->setBusy(false);
-}
-
-
-void GuiWorkArea::updateScrollbar()
-{
- buffer_view_->updateScrollbar();
- ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
- setScrollbarParams(scroll_.height, scroll_.position,
- scroll_.lineScrollHeight);
+ need_resize_ = false;
}
y -= asc;
// if it doesn't touch the screen, don't try to show it
- if (y + h < 0 || y >= height())
+ if (y + h < 0 || y >= viewport()->height())
return;
cursor_visible_ = true;
// Use this opportunity to deal with any child processes that
// have finished but are waiting to communicate this fact
// to the rest of LyX.
- ForkedcallsController & fcc = ForkedcallsController::get();
- fcc.handleCompletedProcesses();
-
- cursor_timeout_.restart();
+ support::ForkedCallsController::handleCompletedProcesses();
}
-void GuiWorkArea::setScrollbarParams(int h, int scroll_pos, int scroll_line_step)
+void GuiWorkArea::updateScrollbar()
{
- if (verticalScrollBarPolicy() != Qt::ScrollBarAlwaysOn)
- setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
-
verticalScrollBar()->setTracking(false);
+ buffer_view_->updateScrollbar();
+ ScrollbarParameters const & scroll_ = buffer_view_->scrollbarParameters();
+
// do what cursor movement does (some grey)
- h += height() / 4;
- int scroll_max_ = std::max(0, h - height());
+ int const h = scroll_.height + viewport()->height() / 4;
+ int scroll_max_ = std::max(0, h - viewport()->height());
verticalScrollBar()->setRange(0, scroll_max_);
- verticalScrollBar()->setSliderPosition(scroll_pos);
- verticalScrollBar()->setSingleStep(scroll_line_step);
- verticalScrollBar()->setValue(scroll_pos);
+ verticalScrollBar()->setSliderPosition(scroll_.position);
+ verticalScrollBar()->setSingleStep(scroll_.lineScrollHeight);
+ verticalScrollBar()->setValue(scroll_.position);
verticalScrollBar()->setTracking(true);
}
if (lyxrc.cursor_follows_scrollbar) {
buffer_view_->setCursorFromScrollbar();
- lyx_view_->updateLayoutChoice(false);
+ lyx_view_->updateLayoutList();
}
// Show the cursor immediately after any operation.
startBlinkingCursor();
#ifdef Q_WS_X11
if (XEventsQueued(QX11Info::display(), 0) > 1 && ev->isAutoRepeat()
&& (Qt::Key_PageDown || Qt::Key_PageUp)) {
- LYXERR(Debug::KEY)
- << BOOST_CURRENT_FUNCTION << endl
- << "system is busy: scroll key event ignored" << endl;
+ LYXERR(Debug::KEY, "system is busy: scroll key event ignored");
ev->ignore();
return;
}
#endif
- LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
- << " count=" << ev->count()
- << " text=" << fromqstr(ev->text())
- << " isAutoRepeat=" << ev->isAutoRepeat()
- << " key=" << ev->key()
- << endl;
+ LYXERR(Debug::KEY, " count: " << ev->count()
+ << " text: " << fromqstr(ev->text())
+ << " isAutoRepeat: " << ev->isAutoRepeat() << " key: " << ev->key());
KeySymbol sym;
setKeySymbol(&sym, ev);
void GuiWorkArea::paintEvent(QPaintEvent * ev)
{
QRect const rc = ev->rect();
- /*
- LYXERR(Debug::PAINTING) << "paintEvent begin: x: " << rc.x()
- << " y: " << rc.y()
- << " w: " << rc.width()
- << " h: " << rc.height() << endl;
- */
+ // LYXERR(Debug::PAINTING, "paintEvent begin: x: " << rc.x()
+ // << " y: " << rc.y() << " w: " << rc.width() << " h: " << rc.height());
if (need_resize_) {
verticalScrollBar()->setPageStep(viewport()->height());
updateScreen();
hideCursor();
showCursor();
- need_resize_ = false;
}
QPainter pain(viewport());
}
-void GuiWorkArea::expose(int x, int y, int w, int h)
-{
- updateScreen();
- update(x, y, w, h);
-}
-
-
-void GuiWorkArea::setWindowTitle(docstring const & t, docstring const & it)
-{
- QString title = windowTitle();
- QString new_title = toqstr(t);
- if (title == new_title)
- return;
-
- QWidget::setWindowTitle(new_title);
- QWidget::setWindowIconText(toqstr(it));
- titleChanged(this);
-}
-
-
void GuiWorkArea::updateScreen()
{
GuiPainter pain(&screen_);
- verticalScrollBar()->show();
buffer_view_->draw(pain);
}
if (!commit_string.isEmpty()) {
- LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
- << " preeditString =" << fromqstr(e->preeditString())
- << " commitString =" << fromqstr(e->commitString())
- << endl;
+ LYXERR(Debug::KEY, "preeditString: " << fromqstr(e->preeditString())
+ << " commitString: " << fromqstr(e->commitString()));
int key = 0;
// FIXME Iwami 04/01/07: we should take care also of UTF16 surrogates here.
- for (int i = 0; i < commit_string.size(); ++i) {
+ for (int i = 0; i != commit_string.size(); ++i) {
QKeyEvent ev(QEvent::KeyPress, key, Qt::NoModifier, commit_string[i]);
keyPressEvent(&ev);
}
int cur_y = cursor_->rect().bottom();
// redraw area of preedit string.
- update(0, cur_y - height, GuiWorkArea::width(),
+ update(0, cur_y - height, viewport()->width(),
(height + 1) * preedit_lines_);
if (preedit_string.empty()) {
// cursor_pos : cursor position in preedit string.
size_t cursor_pos = 0;
bool cursor_is_visible = false;
- for (int i = 0; i < att.size(); ++i) {
+ for (int i = 0; i != att.size(); ++i) {
if (att.at(i).type == QInputMethodEvent::Cursor) {
cursor_pos = att.at(i).start;
cursor_is_visible = att.at(i).length != 0;
// rLength : selected string length in IM.
size_t rLength = 0;
if (cursor_pos < preedit_length) {
- for (int i = 0; i < att.size(); ++i) {
+ for (int i = 0; i != att.size(); ++i) {
if (att.at(i).type == QInputMethodEvent::TextFormat) {
if (att.at(i).start <= int(cursor_pos)
&& int(cursor_pos) < att.at(i).start + att.at(i).length) {
ps = Painter::preedit_default;
// if we reached the right extremity of the screen, go to next line.
- if (cur_x + fm.width(typed_char) > GuiWorkArea::width() - right_margin) {
+ if (cur_x + fm.width(typed_char) > viewport()->width() - right_margin) {
cur_x = right_margin;
cur_y += height + 1;
++preedit_lines_;
}
// update the preedit string screen area.
- update(0, cur_y - preedit_lines_*height, GuiWorkArea::width(),
+ update(0, cur_y - preedit_lines_*height, viewport()->width(),
(height + 1) * preedit_lines_);
// Don't forget to accept the event!
maximize_title += _(" (read only)");
}
- setWindowTitle(maximize_title, minimize_title);
+ QString title = windowTitle();
+ QString new_title = toqstr(maximize_title);
+ if (title == new_title)
+ return;
+
+ QWidget::setWindowTitle(new_title);
+ QWidget::setWindowIconText(toqstr(minimize_title));
+ titleChanged(this);
}
{
updateWindowTitle();
if (this == lyx_view_->currentWorkArea())
- lyx_view_->getDialogs().updateBufferDependent(false);
+ lyx_view_->updateBufferDependent(false);
}
this, SLOT(closeCurrentTab()));
setCornerWidget(closeTabButton);
-#if QT_VERSION >= 0x040200
setUsesScrollButtons(true);
-#endif
}
void TabWorkArea::showBar(bool show)
{
+ tabBar()->setEnabled(show);
tabBar()->setVisible(show);
}
}
+GuiWorkArea * TabWorkArea::addWorkArea(Buffer & buffer, GuiView & view)
+{
+ GuiWorkArea * wa = new GuiWorkArea(buffer, view);
+ wa->setUpdatesEnabled(false);
+ // Hide tabbar if there's no tab (avoid a resize and a flashing tabbar
+ // when hiding it again below).
+ showBar(count() > 0);
+ addTab(wa, wa->windowTitle());
+ QObject::connect(wa, SIGNAL(titleChanged(GuiWorkArea *)),
+ this, SLOT(updateTabText(GuiWorkArea *)));
+ // Hide tabbar if there's only one tab.
+ showBar(count() > 1);
+ return wa;
+}
+
+
bool TabWorkArea::removeWorkArea(GuiWorkArea * work_area)
{
BOOST_ASSERT(work_area);
GuiWorkArea * wa = dynamic_cast<GuiWorkArea *>(widget(i));
BOOST_ASSERT(wa);
BufferView & bv = wa->bufferView();
- bv.updateMetrics();
bv.cursor().fixIfBroken();
+ bv.updateMetrics();
wa->setUpdatesEnabled(true);
wa->redraw();
wa->setFocus();
///
currentWorkAreaChanged(wa);
- LYXERR(Debug::GUI) << "currentTabChanged " << i
- << "File" << bv.buffer().absFileName() << endl;
+ LYXERR(Debug::GUI, "currentTabChanged " << i
+ << "File" << bv.buffer().absFileName());
}