Ejemplo n.º 1
0
void GraphicsBoard::paint(QPainter* painter,
			  const QStyleOptionGraphicsItem* option,
			  QWidget* widget)
{
	Q_UNUSED(option);
	Q_UNUSED(widget);

	QRectF rect(m_rect.topLeft(), QSizeF(m_squareSize, m_squareSize));
	const qreal rLeft = rect.left();

	// paint squares
	for (int y = 0; y < m_ranks; y++)
	{
		rect.moveLeft(rLeft);
		for (int x = 0; x < m_files; x++)
		{
			if ((x % 2) == (y % 2))
				painter->fillRect(rect, m_lightColor);
			else
				painter->fillRect(rect, m_darkColor);
			rect.moveLeft(rect.left() + m_squareSize);
		}
		rect.moveTop(rect.top() + m_squareSize);
	}

	auto font = painter->font();
	font.setPointSizeF(font.pointSizeF() * 0.7);
	painter->setFont(font);

	// paint file coordinates
	const QString alphabet = "abcdefghijklmnopqrstuvwxyz";
	for (int i = 0; i < m_files; i++)
	{
		const qreal tops[] = {m_rect.top() - m_coordSize,
		                      m_rect.bottom()};
		for (const auto top : tops)
		{
			rect = QRectF(m_rect.left() + (m_squareSize * i), top,
			              m_squareSize, m_coordSize);
			int file = m_flipped ? m_files - i - 1 : i;
			painter->drawText(rect, Qt::AlignCenter, alphabet[file]);
		}
	}

	// paint rank coordinates
	for (int i = 0; i < m_ranks; i++)
	{
		const qreal lefts[] = {m_rect.left() - m_coordSize,
		                       m_rect.right()};
		for (const auto left : lefts)
		{
			rect = QRectF(left, m_rect.top() + (m_squareSize * i),
			              m_coordSize, m_squareSize);
			int rank = m_flipped ? i + 1 : m_ranks - i;
			const auto num = QString::number(rank);
			painter->drawText(rect, Qt::AlignCenter, num);
		}
	}
}
Ejemplo n.º 2
0
AudioEqualizerDialog::AudioEqualizerDialog(QWidget *parent)
    : QDialog(parent), d(new Data)
{
    d->p = this;

    auto vbox = new QVBoxLayout;

    auto hbox = new QHBoxLayout;

    hbox->addWidget(new QLabel(tr("Preset")));
    d->presets = new QComboBox;
    d->presets->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
    for (int i = 0; i < Eq::MaxPreset; ++i)
        d->presets->addItem(AudioEqualizer::name((Preset)i), i);
    auto sig = static_cast<Signal<QComboBox, int>>(&QComboBox::currentIndexChanged);
    auto load = [=] () {
        auto data = d->presets->currentData();
        if (data.type() == (int)QMetaType::Int)
            setEqualizer(Eq(Preset(data.toInt())));
    };
    connect(d->presets, sig, this, load);
    hbox->addWidget(d->presets);

    auto button = new QPushButton(tr("Load"));
    connect(button, &QPushButton::clicked, this, load);
    hbox->addWidget(button);
    vbox->addLayout(hbox);

    hbox = new QHBoxLayout;
    auto font = this->font();
    font.setPointSizeF(font.pointSizeF()*0.8);
    const int w = QFontMetrics(font).width(u"+20.0dB"_q) + 2;
    for (int i = 0; i < Eq::bands(); ++i) {
        auto s = d->sliders[i] = new QSlider;
        s->setOrientation(Qt::Vertical);
        s->setRange(Eq::min() * Factor, Eq::max() * Factor);
        s->setFixedWidth(w);
        auto vbox = new QVBoxLayout;
        const auto f = Eq::freqeuncy(i);
        const QString fq = f < 999.9 ? (QString::number(f) % "Hz"_a)
                                     : (QString::number(f/1000.0) % "kHz"_a);
        auto label = new QLabel(fq);
        label->setFont(font);
        label->setAlignment(Qt::AlignCenter);
        vbox->addWidget(label);
        vbox->addWidget(s);
        auto dB = new QLabel("0.0dB"_a);
        dB->setFont(font);
        dB->setAlignment(Qt::AlignCenter);
        vbox->addWidget(dB);
        hbox->addLayout(vbox);

        connect(s, &QSlider::valueChanged, this, [=] () {
            const auto v = s->value()/(double)Factor;
            dB->setText((v > 0 ? "+"_a : ""_a) % QString::number(v, 'f', 1) % "dB"_a);
            if (_Change(d->eq[i], v) && d->update)
                d->update(d->eq);
        });
    }
    vbox->addLayout(hbox);
    setLayout(vbox);

    _SetWindowTitle(this, tr("Audio Equalizer"));
}