1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/* TRANSLATOR BALL::VIEW::DragLogView
Necessary for lupdate.
*/
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/VIEW/WIDGETS/logView.h>
#include <BALL/VIEW/KERNEL/mainControl.h>
#include <BALL/VIEW/KERNEL/message.h>
#include <QtCore/QMimeData>
#include <QtGui/QTextCursor>
using namespace std;
namespace BALL
{
namespace VIEW
{
DragLogView::DragLogView(QWidget* parent)
: QTextBrowser(parent)
{
}
void DragLogView::contentsDragEnterEvent(QDragEnterEvent* e)
{
if (e->mimeData()->hasUrls()) e->acceptProposedAction();
setReadOnly(false);
}
void DragLogView::contentsDragLeaveEvent(QDragLeaveEvent*)
{
setReadOnly(true);
}
void DragLogView::contentsDropEvent(QDropEvent *e)
{
VIEW::processDropEvent(e);
setReadOnly(true);
}
void DragLogView::setSource(const QUrl& /* name */)
{ }
LogView::LogView(QWidget *parent, const char *name)
: DockWidget(parent, name),
LogStreamNotifier(),
text_edit_(new DragLogView(this))
{
default_visible_ = false;
setGuest(*text_edit_);
text_edit_->setLineWrapMode(QTextEdit::WidgetWidth);
text_edit_->setAcceptRichText(false);
text_edit_->setReadOnly(true);
registerWidget(this);
qApp->installEventFilter(this);
}
LogView::LogView(const LogView& view)
: DockWidget((QWidget*)view.getParent()),
LogStreamNotifier(),
text_edit_(new DragLogView(this))
{
default_visible_ = false;
setGuest(*text_edit_);
}
LogView::~LogView()
{
#ifdef BALL_VIEW_DEBUG
Log.error() << "Destructing object " << (void *)this
<< " of class LogView" << endl;
#endif
}
void LogView::logNotify()
{
char c;
stream_.get(c);
String line;
while (stream_.gcount() > 0)
{
line += c;
stream_.get(c);
}
stream_.clear();
if (line.size() > 0)
{
LogEvent* su = new LogEvent;
su->setMessage(line);
su->setShowOnlyInLogView(true);
qApp->postEvent(getMainControl(), su); // Qt will delete it when done
}
}
void LogView::logString(const String& text)
{
setUpdatesEnabled(false);
QTextCursor ct = text_edit_->textCursor();
if (!ct.atEnd()) {
ct.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
text_edit_->setTextCursor(ct);
}
text_edit_->insertPlainText(text.c_str());
ct.movePosition(QTextCursor::End, QTextCursor::MoveAnchor);
text_edit_->setTextCursor(ct);
text_edit_->ensureCursorVisible();
setUpdatesEnabled(true);
}
void LogView::initializeWidget(MainControl& main_control)
{
registerAt(Log);
text_edit_->setReadOnly(true);
DockWidget::initializeWidget(main_control);
insertMenuEntry(MainControl::EDIT, tr("Clear Logs"), text_edit_, SLOT(clear()),
"Shortcut|MainControl|Edit|ClearLogs", QKeySequence(), tr(""),
UIOperationMode::MODE_ADVANCED);
}
void LogView::finalizeWidget(MainControl& main_control)
{
DockWidget::finalizeWidget(main_control);
LogStreamNotifier::unregister();
}
void LogView::showGuestContextMenu(const QPoint& pos)
{
QMenu* menu = text_edit_->createStandardContextMenu();
menu->exec(mapToGlobal(pos));
delete menu;
}
bool LogView::eventFilter(QObject*, QEvent* e)
{
if (e->type() == (QEvent::Type)LOG_EVENT)
{
LogEvent* so = dynamic_cast<LogEvent*>(e);
logString(so->getMessage());
if (!so->showOnlyInLogView()) getMainControl()->setStatusbarText(so->getMessage(), so->isImportant());
return true;
}
return false;
}
} // VIEW
} // namespace BALL
|