| 1 | #include "decoder_config.h" |
| 2 | #include "decoder_config.moc" |
| 3 | |
| 4 | #include "playercontrol.h" |
| 5 | |
| 6 | #include "avm_creators.h" |
| 7 | #include "videodecoder.h" |
| 8 | #include "renderer.h" |
| 9 | #include "avm_except.h" |
| 10 | |
| 11 | #include <qgroupbox.h> |
| 12 | #include <qlabel.h> |
| 13 | #include <qlayout.h> |
| 14 | #include <qpushbutton.h> |
| 15 | #include <qslider.h> |
| 16 | |
| 17 | #ifndef Qt4 |
| 18 | #include <qhbox.h> |
| 19 | #else |
| 20 | #include <qboxlayout.h> |
| 21 | #endif |
| 22 | |
| 23 | |
| 24 | #include <stdio.h> |
| 25 | |
| 26 | QConfDialog::QConfDialog(const avm::vector<avm::AttributeInfo>& _attrs) |
| 27 | :QDialog(0, "", true), attrs(_attrs) |
| 28 | { |
| 29 | #if QT_VERSION > 220 |
| 30 | setSizeGripEnabled( TRUE ); |
| 31 | #endif |
| 32 | |
| 33 | QVBoxLayout *top_vbl = new QVBoxLayout(this, 5); |
| 34 | top_vbl->setSpacing(2); |
| 35 | //m_pTabAttr = new QListView( gb ); |
| 36 | |
| 37 | sliders.resize(attrs.size()); |
| 38 | original.resize(attrs.size()); |
| 39 | |
| 40 | for (size_t i = 0; i < attrs.size(); ++i) |
| 41 | { |
| 42 | sliders[i] = 0; |
| 43 | if (attrs[i].kind == avm::AttributeInfo::Integer) |
| 44 | { |
| 45 | if (attrs[i].i_min + 0 >= attrs[i].i_max) |
| 46 | continue;//integers with unlimited values |
| 47 | //and boolean attributes are not supported |
| 48 | QGroupBox* box = new QGroupBox( this ); |
| 49 | box->setTitle( attrs[i].GetAbout() ); |
| 50 | box->setColumnLayout( |
| 51 | #if QT_VERSION > 220 |
| 52 | 0, |
| 53 | #else |
| 54 | 1, // there is bug and 0 doesn't work |
| 55 | #endif |
| 56 | Qt::Vertical ); |
| 57 | |
| 58 | top_vbl->addWidget(box); |
| 59 | QVBoxLayout *box_vbl = new QVBoxLayout( box->layout() ); |
| 60 | |
| 61 | int pgs = 1; |
| 62 | if (attrs[i].i_max - attrs[i].i_min > 20) |
| 63 | pgs = (attrs[i].i_max - attrs[i].i_min) / 10; |
| 64 | |
| 65 | QSlider* slider = new QSlider( attrs[i].i_min, attrs[i].i_max, pgs, 0, QSlider::Horizontal, box ); |
| 66 | #if QT_VERSION > 220 |
| 67 | slider->setLineStep(1); |
| 68 | #endif |
| 69 | sliders[i] = slider; |
| 70 | box_vbl->addWidget(slider); |
| 71 | slider->setTickmarks(QSlider::Both); |
| 72 | |
| 73 | QGridLayout *box_hbl = new QGridLayout( box_vbl, 1, 1 ); |
| 74 | char txt[100]; |
| 75 | sprintf(txt, "%d", attrs[i].i_min); |
| 76 | QLabel* label = new QLabel( txt, box ); |
| 77 | box_hbl->addWidget(label, 0, 0); |
| 78 | sprintf(txt, "%d", attrs[i].i_max); |
| 79 | label = new QLabel( txt, box ); |
| 80 | box_hbl->setColStretch(1, 1); |
| 81 | box_hbl->addWidget(label, 0, 2); |
| 82 | } |
| 83 | //other types of atributes are not supported |
| 84 | } |
| 85 | |
| 86 | top_vbl->addStretch(1); |
| 87 | |
| 88 | QHBox* hbox = new QHBox(this); |
| 89 | top_vbl->addWidget(hbox); |
| 90 | |
| 91 | QPushButton* b_ok = new QPushButton( tr( "&Ok" ), hbox ); |
| 92 | b_ok->setDefault( TRUE ); |
| 93 | QPushButton* b_reset = new QPushButton( tr ( "&Reset" ), hbox ); |
| 94 | QPushButton* b_cancel = new QPushButton( tr( "&Cancel" ), hbox ); |
| 95 | |
| 96 | connect( b_ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); |
| 97 | connect( b_reset, SIGNAL( clicked() ), this, SLOT( reset() ) ); |
| 98 | connect( b_cancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); |
| 99 | } |
| 100 | |
| 101 | void QConfDialog::reject() |
| 102 | { |
| 103 | // restore original values & reject |
| 104 | for (size_t i = 0; i < attrs.size(); ++i) |
| 105 | if (sliders[i] && (original[i] != sliders[i]->value())) |
| 106 | sliders[i]->setValue(original[i]); |
| 107 | |
| 108 | return QDialog::reject(); |
| 109 | } |
| 110 | |
| 111 | void QConfDialog::reset() |
| 112 | { |
| 113 | for (size_t i = 0; i < attrs.size(); ++i) |
| 114 | if (sliders[i]) |
| 115 | sliders[i]->setValue(attrs[i].GetDefault()); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | QCodecConf::QCodecConf( const avm::CodecInfo& _info, avm::IRtConfig* _rt ) |
| 120 | : QConfDialog( _rt ? _rt->GetAttrs() : _info.decoder_info ), |
| 121 | info(_info), rt(_rt) |
| 122 | { |
| 123 | setCaption( tr( "Decoder configuration" ) ); |
| 124 | |
| 125 | for (unsigned i = 0; i < attrs.size(); i++) |
| 126 | { |
| 127 | int val = 0; |
| 128 | if (rt) |
| 129 | rt->GetValue(attrs[i].GetName(), &val); |
| 130 | else |
| 131 | avm::CodecGetAttr(info, attrs[i].GetName(), &val); |
| 132 | if (sliders[i]) |
| 133 | { |
| 134 | sliders[i]->setValue(val); |
| 135 | // so we have arrays of the same length |
| 136 | original[i] = val; |
| 137 | |
| 138 | if (rt) |
| 139 | connect(sliders[i], SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void QCodecConf::valueChanged(int) |
| 145 | { |
| 146 | for (size_t i = 0; i < attrs.size(); ++i) |
| 147 | if (sliders[i]) |
| 148 | { |
| 149 | int v = sliders[i]->value(); |
| 150 | if (rt) |
| 151 | rt->SetValue(attrs[i].GetName(), v); |
| 152 | // store to registers |
| 153 | avm::CodecSetAttr(info, attrs[i].GetName(), v); |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | #define __MODULE__ "RendererConfig" |
| 158 | |
| 159 | QRendererConf::QRendererConf( const avm::vector<avm::AttributeInfo>& _attrs, avm::IRtConfig* _rt ) |
| 160 | : QConfDialog( _attrs ), rt(_rt) |
| 161 | { |
| 162 | if (!rt) |
| 163 | throw FATAL("Missing IRtConfig"); |
| 164 | |
| 165 | setCaption( tr( "Renderer configuration" ) ); |
| 166 | |
| 167 | for (size_t i = 0; i < attrs.size(); ++i) |
| 168 | { |
| 169 | if (sliders[i]) |
| 170 | { |
| 171 | int val = 0; |
| 172 | rt->GetValue(attrs[i].GetName(), &val); |
| 173 | original[i] = val; |
| 174 | |
| 175 | sliders[i]->setValue(val); |
| 176 | connect(sliders[i], SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); |
| 177 | } |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | void QRendererConf::valueChanged(int) |
| 182 | { |
| 183 | for (size_t i = 0; i < attrs.size(); ++i) |
| 184 | if (sliders[i]) |
| 185 | rt->SetValue(attrs[i].GetName(), sliders[i]->value()); |
| 186 | } |