Пример #1
0
WAnchor *WItemDelegate::anchorWidget(WidgetRef& w)
{
  WAnchor *anchor = dynamic_cast<WAnchor *>(w.w->find("a"));
  if (anchor)
    return anchor;

  anchor = new WAnchor();
  anchor->setObjectName("a");

  WContainerWidget *wc = dynamic_cast<WContainerWidget *>(w.w->find("o"));
  if (wc) {
    /*
     * Convert (2) -> (4)
     */
    int firstToMove = 0;

    WCheckBox *cb = dynamic_cast<WCheckBox *>(wc->widget(0));
    if (cb)
      firstToMove = 1;

    wc->insertWidget(firstToMove, anchor);

    while (wc->count() > firstToMove + 1) { 
      WWidget *c = wc->widget(firstToMove + 1);
      wc->removeWidget(c);
      anchor->addWidget(c);
    }
  } else {
    /*
     * Convert (1) -> (3)
     */
    anchor->addWidget(w.w);
    w.w = anchor;
  }

  return anchor;
}
Пример #2
0
QueueItem::QueueItem(Media media, std::list< QueueItem* >& queue, WContainerWidget* container, Session* session, WContainerWidget* parent)
  : WContainerWidget(parent), PlaylistItem(media)
{
  QueueItem *queueItem = this;
  Dbo::Transaction t(*session);
  WAnchor *anchor = new WAnchor{this};
  anchor->addWidget(WW<WText>(media.title(t)).css("link-hand").onClick([=](WMouseEvent&){ playSignal.emit(this); }));
  WContainerWidget *actionsContainer = WW<WContainerWidget>(anchor).css("pull-right");
  auto fixButtons = [=,&queue] {
    for(QueueItem *item: queue) {
      item->upButton->setHidden(item == queue.front());
      item->downButton->setHidden(item == queue.back());
    }
  };
  
  auto moveElement = [=,&queue](int direction) {
    auto element = std::find(begin(queue), end(queue), queueItem);
    auto nextElement = element;
    direction>0 ? nextElement++ : nextElement--;
    swap(*nextElement, *element);
    int index = container->indexOf(queueItem);
    container->removeWidget(queueItem);
    container->insertWidget(index + direction, queueItem);
    fixButtons();
  };
  
  actionsContainer->addWidget(upButton = WW<WImage>(Settings::staticPath("/icons/actions/up.png"))
    .css("link-hand").onClick([=,&queue](WMouseEvent){
    if(queue.front() == queueItem) return;
    moveElement(-1);
  }));
  actionsContainer->addWidget(downButton = WW<WImage>(Settings::staticPath("/icons/actions/down.png"))
    .css("link-hand").onClick([=,&queue](WMouseEvent){
    if(queue.back() == queueItem) return;
    moveElement(+1);
  }));
  actionsContainer->addWidget(removeButton = WW<WImage>(Settings::staticPath("/icons/actions/delete.png"))
    .css("link-hand").onClick([=,&queue](WMouseEvent){
    queue.erase(std::remove(begin(queue), end(queue), queueItem));
    delete queueItem;
    fixButtons();
  }));
  upButton->setHiddenKeepsGeometry(true);
  downButton->setHiddenKeepsGeometry(true);
  container->addWidget(this);
  queue.push_back(this);
  fixButtons();
}
Пример #3
0
void PostView::render(RenderType type)
{
  if (type != Edit)
    viewType_ = type;

  clear();

  switch (type) {
  case Detail: {
    setTemplateText(tr("blog-post"));

    commentCount_ = new WText(post_->commentCount());

    CommentView *comments = new CommentView(session_, post_->rootComment());
    session_.commentsChanged().connect(this, &PostView::updateCommentCount);

    bindWidget("comment-count", commentCount_);
    bindWidget("comments", comments);
    bindString("anchor", basePath_ + post_->permaLink());

    break;
  }
  case Brief: {
    setTemplateText(tr("blog-post-brief"));

    WAnchor *titleAnchor
      = new WAnchor(WLink(WLink::InternalPath, basePath_ + post_->permaLink()),
		    post_->title);
    bindWidget("title", titleAnchor);

    if (!post_->briefSrc.empty()) {
      WAnchor *moreAnchor 
	= new WAnchor(WLink(WLink::InternalPath,
			    basePath_ + post_->permaLink() + "/more"),
		      tr("blog-read-more"));
      bindWidget("read-more", moreAnchor);
    } else {
      bindString("read-more", WString::Empty);
    }

    commentCount_ = new WText("(" + post_->commentCount() + ")");

    WAnchor *commentsAnchor
      = new WAnchor(WLink(WLink::InternalPath,
			  basePath_ + post_->permaLink() + "/comments"));
    commentsAnchor->addWidget(commentCount_);
    bindWidget("comment-count", commentsAnchor);

    break; }
  case Edit: {
    setTemplateText(tr("blog-post-edit"));

    bindWidget("title-edit", titleEdit_ = new WLineEdit(post_->title));
    bindWidget("brief-edit", briefEdit_ = new WTextArea(post_->briefSrc));
    bindWidget("body-edit", bodyEdit_ = new WTextArea(post_->bodySrc));

    WPushButton *saveButton = new WPushButton(tr("save"));
    WPushButton *cancelButton = new WPushButton(tr("cancel"));
    bindWidget("save", saveButton);
    bindWidget("cancel", cancelButton);

    saveButton->clicked().connect(this, &PostView::saveEdit);
    cancelButton->clicked().connect(this, &PostView::showView);

    break; }
  }

  if (type == Detail || type == Brief) {
    if (session_.user() == post_->author) {
      WPushButton *publishButton;
      if (post_->state != Post::Published) {
	publishButton = new WPushButton(tr("publish"));
	publishButton->clicked().connect(this, &PostView::publish);
      } else {
	publishButton = new WPushButton(tr("retract"));
	publishButton->clicked().connect(this, &PostView::retract);
      }
      bindWidget("publish", publishButton);

      WPushButton *editButton = new WPushButton(tr("edit"));
      editButton->clicked().connect(this, &PostView::showEdit);
      bindWidget("edit", editButton);

      WPushButton *deleteButton = new WPushButton(tr("delete"));
      deleteButton->clicked().connect(this, &PostView::rm);
      bindWidget("delete", deleteButton);
    } else {
      bindString("publish", WString::Empty);
      bindString("edit", WString::Empty);
      bindString("delete", WString::Empty);
    }
  }

  WAnchor *postAnchor
    = new WAnchor(WLink(WLink::InternalPath,
			basePath_ + "author/" + post_->author->name.toUTF8()),
		  post_->author->name);
  bindWidget("author", postAnchor);
}