#include "GuiWorkArea.h"
#include "GuiApplication.h"
-#include "QLPainter.h"
-#include "QKeySymbol.h"
+#include "GuiPainter.h"
+#include "GuiKeySymbol.h"
#include "qt_helpers.h"
-#include "LyXView.h"
+#include "frontends/LyXView.h"
#include "BufferView.h"
-#include "rowpainter.h"
+#include "Color.h"
#include "debug.h"
#include "FuncRequest.h"
-#include "Color.h"
-#include "version.h"
#include "LyXRC.h"
+#include "version.h"
#include "support/filetools.h" // LibFileSearch
-#include "support/os.h"
-#include "support/convert.h"
#include "graphics/GraphicsImage.h"
#include "graphics/GraphicsLoader.h"
+#include <QInputContext>
#include <QLayout>
#include <QMainWindow>
-#include <QMimeData>
-#include <QUrl>
-#include <QDragEnterEvent>
#include <QPainter>
#include <QScrollBar>
#include <QTimer>
-#include <QInputContext>
#include <boost/bind.hpp>
#include <boost/current_function.hpp>
+#ifdef Q_WS_X11
+#include <QX11Info>
+extern "C" int XEventsQueued(Display *display, int mode);
+#endif
+
#ifdef Q_WS_WIN
int const CursorWidth = 2;
#else
int const CursorWidth = 1;
#endif
+#undef KeyPress
+#undef NoModifier
using std::endl;
using std::string;
-namespace os = lyx::support::os;
-
-
namespace lyx {
using support::FileName;
-/// return the LyX key state from Qt's
-static key_modifier::state q_key_state(Qt::KeyboardModifiers state)
-{
- key_modifier::state k = key_modifier::none;
- if (state & Qt::ControlModifier)
- k |= key_modifier::ctrl;
- if (state & Qt::ShiftModifier)
- k |= key_modifier::shift;
- if (state & Qt::AltModifier || state & Qt::MetaModifier)
- k |= key_modifier::alt;
- return k;
-}
-
-
/// return the LyX mouse button state from Qt's
static mouse_button::state q_button_state(Qt::MouseButton button)
{
void draw(QPainter & painter)
{
- // FIXME: do something depending on the cursor shape.
- if (show_ && rect_.isValid())
- painter.fillRect(rect_, color_);
+ if (show_ && rect_.isValid()) {
+ switch (shape_) {
+ case L_SHAPE:
+ painter.fillRect(rect_.x(), rect_.y(), CursorWidth, rect_.height(), color_);
+ painter.setPen(color_);
+ painter.drawLine(rect_.bottomLeft().x() + CursorWidth, rect_.bottomLeft().y(),
+ rect_.bottomRight().x(), rect_.bottomLeft().y());
+ break;
+
+ case REVERSED_L_SHAPE:
+ painter.fillRect(rect_.x() + rect_.height() / 3, rect_.y(), CursorWidth, rect_.height(), color_);
+ painter.setPen(color_);
+ painter.drawLine(rect_.bottomRight().x() - CursorWidth, rect_.bottomLeft().y(),
+ rect_.bottomLeft().x(), rect_.bottomLeft().y());
+ break;
+
+ default:
+ painter.fillRect(rect_, color_);
+ break;
+ }
+ }
}
void update(int x, int y, int h, CursorShape shape)
{
color_ = guiApp->colorCache().get(Color::cursor);
- rect_ = QRect(x, y, CursorWidth, h);
shape_ = shape;
+ switch (shape) {
+ case L_SHAPE:
+ rect_ = QRect(x, y, CursorWidth + h / 3, h);
+ break;
+ case REVERSED_L_SHAPE:
+ rect_ = QRect(x - h / 3, y, CursorWidth + h / 3, h);
+ break;
+ default:
+ rect_ = QRect(x, y, CursorWidth, h);
+ break;
+ }
}
void show(bool set_show = true) { show_ = set_show; }
{}
-GuiWorkArea::GuiWorkArea(int w, int h, int id, LyXView & lyx_view)
- : WorkArea(id, lyx_view), need_resize_(false), schedule_redraw_(false),
+GuiWorkArea::GuiWorkArea(Buffer & buf, LyXView & lv)
+ : WorkArea(buf, lv), need_resize_(false), schedule_redraw_(false),
preedit_lines_(1)
{
screen_ = QPixmap(viewport()->width(), viewport()->height());
viewport()->setCursor(Qt::IBeamCursor);
- resize(w, h);
-
synthetic_mouse_event_.timeout.timeout.connect(
boost::bind(&GuiWorkArea::generateSyntheticMouseEvent,
this));
}
-void GuiWorkArea::adjustViewWithScrollBar(int)
-{
- scrollBufferView(verticalScrollBar()->sliderPosition());
-}
-
-
-void GuiWorkArea::dragEnterEvent(QDragEnterEvent * event)
+void GuiWorkArea::adjustViewWithScrollBar(int action)
{
- if (event->mimeData()->hasUrls())
- event->accept();
- /// \todo Ask lyx-devel is this is enough:
- /// if (event->mimeData()->hasFormat("text/plain"))
- /// event->acceptProposedAction();
-}
-
-
-void GuiWorkArea::dropEvent(QDropEvent* event)
-{
- QList<QUrl> files = event->mimeData()->urls();
- if (files.isEmpty())
- return;
+ stopBlinkingCursor();
+ if (action == QAbstractSlider::SliderPageStepAdd)
+ buffer_view_->scrollDown(viewport()->height());
+ else if (action == QAbstractSlider::SliderPageStepSub)
+ buffer_view_->scrollUp(viewport()->height());
+ else
+ buffer_view_->scrollDocView(verticalScrollBar()->sliderPosition());
- LYXERR(Debug::GUI) << "GuiWorkArea::dropEvent: got URIs!" << endl;
- for (int i = 0; i!=files.size(); ++i) {
- string const file = os::internal_path(fromqstr(files.at(i).toLocalFile()));
- if (!file.empty())
- dispatch(FuncRequest(LFUN_FILE_OPEN, file));
+ if (lyxrc.cursor_follows_scrollbar) {
+ buffer_view_->setCursorFromScrollbar();
+ lyx_view_->updateLayoutChoice();
}
+ // Show the cursor immediately after any operation.
+ startBlinkingCursor();
+ QApplication::syncX();
}
// if (theApp() == 0 || &lyx_view_ == theApp()->currentView())
// return;
- theApp()->setCurrentView(lyx_view_);
+ theApp()->setCurrentView(*lyx_view_);
// Repaint the whole screen.
// Note: this is different from redraw() as only the backing pixmap
// will be redrawn, which is cheap.
viewport()->repaint();
- // FIXME: it would be better to send a signal "newBuffer()"
- // in BufferList that could be connected to the different tabbars.
- lyx_view_.updateTab();
-
startBlinkingCursor();
}
void GuiWorkArea::keyPressEvent(QKeyEvent * e)
{
+ // do nothing if there are other events
+ // (the auto repeated events come too fast)
+ // \todo FIXME: remove hard coded Qt keys, process the key binding
+#ifdef Q_WS_X11
+ if (XEventsQueued(QX11Info::display(), 0) > 1 && e->isAutoRepeat()
+ && (Qt::Key_PageDown || Qt::Key_PageUp)) {
+ LYXERR(Debug::KEY)
+ << BOOST_CURRENT_FUNCTION << endl
+ << "system is busy: scroll key event ignored" << endl;
+ e->ignore();
+ return;
+ }
+#endif
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
<< " count=" << e->count()
<< " key=" << e->key()
<< endl;
- boost::shared_ptr<QKeySymbol> sym(new QKeySymbol);
+ boost::shared_ptr<GuiKeySymbol> sym(new GuiKeySymbol);
sym->set(e);
processKeySym(sym, q_key_state(e->modifiers()));
}
-void GuiWorkArea::doubleClickTimeout() {
+
+void GuiWorkArea::doubleClickTimeout()
+{
dc_event_.active = false;
}
+
void GuiWorkArea::mouseDoubleClickEvent(QMouseEvent * e)
{
dc_event_ = double_click(e);
}
-void GuiWorkArea::doGreyOut(QLPainter & pain)
-{
- pain.fillRectangle(0, 0, width(), height(),
- Color::bottomarea);
-
- //if (!lyxrc.show_banner)
- // return;
- LYXERR(Debug::GUI) << "show banner: " << lyxrc.show_banner << endl;
- /// The text to be written on top of the pixmap
- QString const text = lyx_version ? QString(lyx_version) : qt_("unknown version");
- FileName const file = support::libFileSearch("images", "banner", "png");
- if (file.empty())
- return;
-
- QPixmap pm(toqstr(file.absFilename()));
- if (!pm) {
- lyxerr << "could not load splash screen: '" << file << "'" << endl;
- return;
- }
-
- QFont font;
- // The font used to display the version info
- font.setStyleHint(QFont::SansSerif);
- font.setWeight(QFont::Bold);
- font.setPointSize(convert<int>(lyxrc.font_sizes[Font::SIZE_LARGE]));
-
- int const w = pm.width();
- int const h = pm.height();
-
- int x = (width() - w) / 2;
- int y = (height() - h) / 2;
-
- pain.drawPixmap(x, y, pm);
-
- x += 260;
- y += 270;
-
- pain.setPen(QColor(255, 255, 0));
- pain.setFont(font);
- pain.drawText(x, y, text);
-}
-
-
void GuiWorkArea::paintEvent(QPaintEvent * ev)
{
QRect const rc = ev->rect();
screen_ = QPixmap(viewport()->width(), viewport()->height());
resizeBufferView();
updateScreen();
+ WorkArea::hideCursor();
+ WorkArea::showCursor();
need_resize_ = false;
}
void GuiWorkArea::updateScreen()
{
- QLPainter pain(&screen_);
-
- if (greyed_out_) {
- LYXERR(Debug::GUI) << "splash screen requested" << endl;
- verticalScrollBar()->hide();
- doGreyOut(pain);
- return;
- }
-
+ GuiPainter pain(&screen_);
verticalScrollBar()->show();
- paintText(*buffer_view_, pain);
+ buffer_view_->draw(pain);
}
void GuiWorkArea::showCursor(int x, int y, int h, CursorShape shape)
{
if (schedule_redraw_) {
- if (buffer_view_ && buffer_view_->buffer()) {
- buffer_view_->update(Update::Force);
- updateScreen();
- viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
- }
+ buffer_view_->update(Update::Force);
+ updateScreen();
+ viewport()->update(QRect(0, 0, viewport()->width(), viewport()->height()));
schedule_redraw_ = false;
// Show the cursor immediately after the update.
hideCursor();
docstring const & preedit_string
= qstring_to_ucs4(e->preeditString());
- if(greyed_out_) {
- e->ignore();
- return;
- }
-
if (!commit_string.isEmpty()) {
LYXERR(Debug::KEY) << BOOST_CURRENT_FUNCTION
return;
}
- QLPainter pain(&screen_);
+ GuiPainter pain(&screen_);
buffer_view_->updateMetrics(false);
- paintText(*buffer_view_, pain);
+ buffer_view_->draw(pain);
Font font = buffer_view_->cursor().getFont();
FontMetrics const & fm = theFontMetrics(font);
int height = fm.maxHeight();