예제 #1
0
CentralWidget::CentralWidget():thisData_(ThisDataType(
    new zone_data::CentralWidgetData,
    [](zone_data::CentralWidgetData *arg) {delete arg; })) {
    this->setOrientation(Qt::Horizontal);
    zone_this_data(this);
    var_this_data->listView=new ListView;
    this->addWidget(var_this_data->listView);
    var_this_data->novelWidget=new DingDianNovelWidget;
    this->addWidget(var_this_data->novelWidget);

    {
        auto varSizePolicy=var_this_data->listView->sizePolicy();
        varSizePolicy.setHorizontalStretch(0);
        var_this_data->listView->setSizePolicy(varSizePolicy);
    }

    {
        auto varSizePolicy=var_this_data->novelWidget->sizePolicy();
        varSizePolicy.setHorizontalStretch(1);
        var_this_data->novelWidget->setSizePolicy(varSizePolicy);
    }
    /*设置listview 样式*/
    std::shared_ptr<std::function<QWidget*(QWidget*,QModelIndex)>> createFunction=
        std::shared_ptr<std::function<QWidget*(QWidget*,QModelIndex)>>(
            new std::function<QWidget*(QWidget*,QModelIndex)>{
        [](QWidget* argParent,QModelIndex) ->QWidget * {
        ItemWidget * varAns=new ItemWidget(argParent);
        return varAns;
    }/*~lambda function*/
    });
    var_this_data->listView->setCreateFunction(createFunction);
    /*设置model*/
    if (var_this_data->listView->model()) {
        var_this_data->listView->model()->deleteLater();
    }
    var_this_data->listView->setModel(new DingDianModel);

    {
        auto varStyle=DingDianSytle::instance();
        auto varNovelLayout=std::make_shared<NovelLayout>();
        auto varFont=varNovelLayout->font();
        varFont.setPixelSize(varStyle->fontPixSize());
        varFont.setWeight(QFont::Medium);
        varNovelLayout->setFont(varFont);
        varNovelLayout->setDrawColor(varStyle->fontColor());
        var_this_data->novelWidget->setNovelLayout(varNovelLayout);
    }

    connect(
        var_this_data->listView,
        &ListView::onCurrentChanged,
        this,
        [this]() {
        zone_this_data(this);
        this->onCurrentChanged(var_this_data->showLastPage);
        var_this_data->showLastPage=false;
    });

    connect(
        var_this_data->novelWidget,
        &NovelWidget::nextPageEndl,
        this,[var_this_data]() {
        var_this_data->novelWidget->onKeyPressed(Qt::Key_Down);
    });

    connect(
        var_this_data->novelWidget,
        &NovelWidget::previousPageEndl,
        this,[var_this_data]() {
        var_this_data->showLastPage=true;
        var_this_data->novelWidget->onKeyPressed(Qt::Key_Up);
    });

    connect(
        var_this_data->novelWidget,
        &NovelWidget::onKeyPressed,
        this,
        [var_this_data](Qt::Key argKey) {
        if (argKey==Qt::Key_Up) {
            auto varListView=var_this_data->listView;
            auto *varModel=varListView->model();
            auto varIndex=varModel->index(
                std::max(0,varListView->currentIndex().row()-1),
                0);
            varListView->setCurrentIndex(varIndex);
        }
        else if (argKey==Qt::Key_Down) {
            auto varListView=var_this_data->listView;
            auto *varModel=varListView->model();
            auto varIndex=varModel->index(
                std::min(
                std::max(0,varModel->rowCount()-1),
                1+varListView->currentIndex().row()),
                0);
            varListView->setCurrentIndex(varIndex);
        }
    });
}
예제 #2
0
void
ValuePage::init() {
  m_lTitle = new QLabel{this};
  m_lTitle->setWordWrap(true);

  auto line = new QFrame{this};
  line->setFrameShape(QFrame::HLine);
  line->setFrameShadow(QFrame::Sunken);

  m_lTypeLabel    = new QLabel{this};
  m_lType         = new QLabel{this};

  auto sizePolicy = QSizePolicy{QSizePolicy::Expanding, QSizePolicy::Preferred};
  sizePolicy.setHorizontalStretch(0);
  sizePolicy.setVerticalStretch(0);
  sizePolicy.setHeightForWidth(m_lType->sizePolicy().hasHeightForWidth());
  m_lType->setSizePolicy(sizePolicy);

  if (!m_description.get_untranslated().empty()) {
    m_lDescriptionLabel = new QLabel{this};
    m_lDescription      = new QLabel{this};
    sizePolicy.setHeightForWidth(m_lDescription->sizePolicy().hasHeightForWidth());
    m_lDescription->setSizePolicy(sizePolicy);
    m_lDescription->setWordWrap(true);
  }

  m_lStatusLabel  = new QLabel{this};
  m_lStatus       = new QLabel{this};
  m_cbAddOrRemove = new QCheckBox{this};

  if (m_present) {
    auto semantic = find_ebml_semantic(KaxSegment::ClassInfos, m_callbacks.GlobalId);
    if (semantic && semantic->Mandatory)
      m_cbAddOrRemove->setEnabled(false);
  }

  sizePolicy.setHeightForWidth(m_lStatus->sizePolicy().hasHeightForWidth());
  m_lStatus->setSizePolicy(sizePolicy);
  m_lStatus->setWordWrap(true);

  if (m_present) {
    m_lOriginalValueLabel = new QLabel{this};
    m_lOriginalValue      = new QLabel{this};
  }

  m_lValueLabel = new QLabel{this};
  m_input       = createInputControl();
  m_input->setEnabled(m_present);

  m_bReset = new QPushButton{this};

  // ----------------------------------------------------------------------

  auto statusLayout = new QVBoxLayout{};
  statusLayout->addWidget(m_lStatus);
  statusLayout->addWidget(m_cbAddOrRemove);

  auto row        = 0;
  auto gridLayout = new QGridLayout{};
  gridLayout->addWidget(m_lTypeLabel,            row,   0, 1, 1);
  gridLayout->addWidget(m_lType,                 row++, 1, 1, 1);

  if (!m_description.get_untranslated().empty()) {
    gridLayout->addWidget(m_lDescriptionLabel,   row,   0, 1, 1, Qt::AlignTop);
    gridLayout->addWidget(m_lDescription,        row++, 1, 1, 1, Qt::AlignTop);
  }

  gridLayout->addWidget(m_lStatusLabel,          row,   0, 1, 1, Qt::AlignTop);
  gridLayout->addLayout(statusLayout,            row++, 1, 1, 1, Qt::AlignTop);

  if (m_present) {
    gridLayout->addWidget(m_lOriginalValueLabel, row,   0, 1, 1);
    gridLayout->addWidget(m_lOriginalValue,      row++, 1, 1, 1);
  }

  gridLayout->addWidget(m_lValueLabel,           row,   0, 1, 1);
  gridLayout->addWidget(m_input,                 row++, 1, 1, 1);

  auto resetLayout = new QHBoxLayout{};
  resetLayout->addItem(new QSpacerItem{0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum});
  resetLayout->addWidget(m_bReset);

  auto widgetLayout = new QVBoxLayout{this};
  widgetLayout->addWidget(m_lTitle);
  widgetLayout->addWidget(line);
  widgetLayout->addLayout(gridLayout);
  widgetLayout->addItem(new QSpacerItem{0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding});
  widgetLayout->addLayout(resetLayout);

  // ----------------------------------------------------------------------

  connect(m_cbAddOrRemove, SIGNAL(toggled(bool)), this, SLOT(onAddOrRemoveChecked()));
  connect(m_bReset,        SIGNAL(clicked()),     this, SLOT(onResetClicked()));

  // ----------------------------------------------------------------------

  m_parent.appendPage(this, m_topLevelPage.m_pageIdx);

  m_topLevelPage.m_children << this;

  retranslateUi();
}