53 #include "loggerWidget.hh"
59 LoggerWidget::LoggerWidget( QWidget *parent)
66 setAttribute(Qt::WA_DeleteOnClose,
false);
68 QVBoxLayout* vlayout =
new QVBoxLayout();
69 QHBoxLayout* hlayout =
new QHBoxLayout();
71 list_ =
new QListWidget();
73 list_->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
74 list_->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
75 list_->setFocusPolicy(Qt::NoFocus);
76 list_->setSelectionMode(QAbstractItemView::ExtendedSelection);
77 list_->setUniformItemSizes(
true);
79 QString path = OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator();
84 context_ =
new QMenu(tr(
"Log Viewer"));
86 QAction* copyAction =
new QAction(QIcon(path +
"edit-copy.png"), tr(
"Copy"),0);
87 copyAction->setShortcut( QKeySequence(
"Ctrl+C") );
88 QAction* selectAction =
new QAction(tr(
"Select All"),0);
89 selectAction->setShortcut( QKeySequence(
"Ctrl+A") );
91 connect (copyAction, SIGNAL(triggered()),
this, SLOT(copySelected()));
92 connect (selectAction, SIGNAL(triggered()), list_, SLOT(selectAll()));
94 context_->addAction(copyAction);
95 context_->addSeparator();
96 context_->addAction(selectAction);
102 filterMenu_ =
new QMenu(tr(
"Log Viewer"));
104 openMeshFilterAction_ =
new QAction(QIcon(path +
"edit-copy.png"), tr(
"Enable OpenMesh error messages"),0);
105 openMeshFilterAction_->setCheckable(
true);
109 openMeshFilterAction_->setChecked(
true );
112 openMeshFilterAction_->setChecked(
false );
116 filterMenu_->addAction(openMeshFilterAction_);
123 connect (&loggerUpdateTimer_, SIGNAL(timeout ()),
this, SLOT(slotScrollUpdate()));
126 loggerUpdateTimer_.setSingleShot(
true);
127 loggerUpdateTimer_.setInterval(500);
129 allButton_ =
new QPushButton(QIcon(path +
"status_all.png"),tr(
"All Messages"));
130 allButton_->setCheckable(
true);
131 allButton_->setAutoExclusive(
true);
132 infoButton_ =
new QPushButton(QIcon(path +
"status_green.png"),tr(
"Informations"));
133 infoButton_->setCheckable(
true);
134 infoButton_->setAutoExclusive(
true);
135 warnButton_ =
new QPushButton(QIcon(path +
"status_yellow.png"),tr(
"Warnings"));
136 warnButton_->setCheckable(
true);
137 warnButton_->setAutoExclusive(
true);
138 errorButton_ =
new QPushButton(QIcon(path +
"status_red.png"),tr(
"Errors"));
139 errorButton_->setCheckable(
true);
140 errorButton_->setAutoExclusive(
true);
142 filterButton_ =
new QPushButton(QIcon(path +
"status_filter.png"),tr(
"Set Filters"));
143 filterButton_->setCheckable(
false);
145 allButton_->setChecked(
true);
147 connect(allButton_, SIGNAL(clicked()),
this, SLOT(updateList()));
148 connect(infoButton_, SIGNAL(clicked()),
this, SLOT(updateList()));
149 connect(warnButton_, SIGNAL(clicked()),
this, SLOT(updateList()));
150 connect(errorButton_, SIGNAL(clicked()),
this, SLOT(updateList()));
151 connect(filterButton_,SIGNAL(clicked()),
this, SLOT(slotFilterMenu()));
153 clearButton_ =
new QPushButton(QIcon(path +
"edit-clear.png"),tr(
"Clear Messages"));
154 connect(clearButton_, SIGNAL(clicked()), list_, SLOT(clear()));
156 hlayout->addWidget( allButton_ );
157 hlayout->addWidget( infoButton_ );
158 hlayout->addWidget( warnButton_ );
159 hlayout->addWidget( errorButton_ );
160 hlayout->addStretch();
161 hlayout->addWidget( filterButton_ );
162 hlayout->addStretch();
163 hlayout->addWidget( clearButton_ );
165 hlayout->setSpacing(0);
166 hlayout->setContentsMargins (0,0,0,0);
167 vlayout->setSpacing(0);
168 vlayout->setContentsMargins (0,0,0,0);
170 vlayout->addWidget(list_);
171 vlayout->addLayout( hlayout );
173 setLayout( vlayout );
176 LoggerWidget::~LoggerWidget()
193 list_->addItem(_text);
195 QListWidgetItem* item = list_->item( list_->count()-1 );
197 if ( allButton_->isChecked() )
198 item->setHidden(
false);
200 item->setHidden(
true);
204 item->setForeground( QBrush(QColor(Qt::darkGreen)) );
205 item->setBackground( QBrush(QColor(225,255,225), Qt::Dense4Pattern) );
207 if ( infoButton_->isChecked() )
208 item->setHidden(
false);
211 item->setForeground( QBrush(QColor(Qt::black)) );
214 item->setForeground( QBrush(QColor(160,160,0)) );
215 item->setBackground( QBrush(QColor(255,240,200),Qt::Dense4Pattern) );
217 if ( warnButton_->isChecked() )
218 item->setHidden(
false);
221 item->setForeground( QBrush(QColor(Qt::red)) );
222 item->setBackground( QBrush(QColor(255,225,225),Qt::Dense4Pattern) );
224 if ( errorButton_->isChecked() )
225 item->setHidden(
false);
228 item->setForeground( QBrush(QColor(Qt::blue)) );
229 item->setBackground( QBrush(QColor(255,225,225),Qt::Dense4Pattern) );
231 if ( errorButton_->isChecked() )
232 item->setHidden(
false);
247 if ( ! loggerUpdateTimer_.isActive() ) {
249 list_->scrollToBottom();
256 loggerUpdateTimer_.start();
267 list_->scrollToBottom();
280 if ( infoButton_->isChecked() )
281 color = QColor(Qt::darkGreen);
282 else if ( warnButton_->isChecked() )
283 color = QColor(160,160,0);
284 else if ( errorButton_->isChecked() )
285 color = QColor(Qt::red);
287 color = QColor(Qt::black);
289 if (color == QColor(Qt::black)){
291 for (
int i=0; i < list_->count(); i++)
292 list_->item( i )->setHidden(
false);
296 for (
int i=0; i < list_->count(); i++)
297 if ( list_->item(i)->foreground().color() == color )
298 list_->item( i )->setHidden(
false);
300 list_->item( i )->setHidden(
true);
303 list_->scrollToBottom();
308 list_->scrollToBottom();
316 if ( (_event->modifiers() & Qt::ControlModifier ) && ( _event->key() == Qt::Key_C ) )
319 else if ( (_event->modifiers() & Qt::ControlModifier ) && ( _event->key() == Qt::Key_A ) )
331 QPoint p = list_->mapToGlobal( event->pos() );
333 context_->popup( p );
344 for (
int i=0; i < list_->selectedItems().count(); i++)
345 str += (list_->selectedItems()[i])->text() +
"\n";
347 QClipboard *clipboard = QApplication::clipboard();
349 clipboard->setText(str);
355 filterMenu_->popup( list_->mapToGlobal(filterButton_->pos()) );
DLLEXPORT OpenFlipperQSettings & OpenFlipperSettings()
QSettings object containing all program settings of OpenFlipper.
void slotScrollUpdate()
Called when we want to scroll to the bottom.
Logtype
Log types for Message Window.
void updateList()
update the list if a button was pressed
void keyPressEvent(QKeyEvent *_event)
Grab key events.
void append(const QString &_text, Logtype _type)
Append a new logmessage to log viewer.
void copySelected()
copy Selected rows to clipboard
void showEvent(QShowEvent *event)
Called when the widget is shown.
void slotFilterMenu()
Called when filter button is pressed.
void contextMenuEvent(QContextMenuEvent *event)
Show context menu.