Widgets displaying colored diff done.
[qshowdiff.git] / src / qt / diff_view.cpp
blob05f4305cca3e35db214836f872e144ab00efd4ef
1 #include <QVBoxLayout>
2 #include <QScrollBar>
3 #include <QPainter>
4 #include <QScrollArea>
6 #include "../debug.h"
7 #include "diff_view.h"
9 DiffViewFrame::DiffViewFrame(QWidget *parent) : QWidget(parent)
11 QVBoxLayout *layout = new QVBoxLayout();
12 QSplitter *splitter = new QSplitter(Qt::Horizontal);
13 DiffView *original = new DiffView(true);
14 DiffView *modified = new DiffView(false);
15 QScrollArea *orig = new QScrollArea();
16 QScrollArea *modif = new QScrollArea();
19 orig->setWidget(original);
20 orig->setWidgetResizable(true);
21 orig->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
22 modif->setWidget(modified);
23 modif->setWidgetResizable(true);
25 splitter->addWidget(orig);
26 splitter->addWidget(modif);
28 layout->addWidget(splitter);
30 setLayout(layout);
33 QScrollBar *orig_vertical = orig->verticalScrollBar();
34 QScrollBar *modif_vertical = modif->verticalScrollBar();
35 QScrollBar *orig_horizontal = orig->horizontalScrollBar();
36 QScrollBar *modif_horizontal = modif->horizontalScrollBar();
38 connect(orig_vertical, SIGNAL(valueChanged(int)), modif_vertical,
39 SLOT(setValue(int)));
40 connect(modif_vertical, SIGNAL(valueChanged(int)), orig_vertical,
41 SLOT(setValue(int)));
42 connect(orig_horizontal, SIGNAL(valueChanged(int)), modif_horizontal,
43 SLOT(setValue(int)));
44 connect(modif_horizontal, SIGNAL(valueChanged(int)), orig_horizontal,
45 SLOT(setValue(int)));
49 /* DiffView */
50 void DiffView::paintEvent(QPaintEvent *e)
52 int height;
53 QPainter painter(this);
54 if (_original){
55 height = Diff::instance()->paintOriginal(painter);
56 }else{
57 height = Diff::instance()->paintModified(painter);
60 setFixedHeight(height);
61 setMinimumWidth(Settings::max_line_width);